1073 lines
21 KiB
NASM
1073 lines
21 KiB
NASM
%include "src/constants.asm"
|
|
|
|
; core.asm
|
|
extern exit
|
|
extern islower
|
|
extern isupper
|
|
extern tolower
|
|
extern toupper
|
|
extern min
|
|
extern minu
|
|
extern max
|
|
extern maxu
|
|
extern clamp
|
|
extern clampu
|
|
; console.asm
|
|
extern print
|
|
extern puts
|
|
extern printf
|
|
; string.asm
|
|
extern strlen
|
|
extern strcpy
|
|
extern strcat
|
|
extern strclr
|
|
extern strcmp
|
|
; convert.asm
|
|
extern itoa
|
|
extern utoa
|
|
|
|
section .rodata
|
|
TEST_print equ 1
|
|
TEST_puts equ 1
|
|
TEST_itoa equ 1 ;includes utoa
|
|
TEST_printf equ 1
|
|
TEST_strlen equ 1
|
|
TEST_strcpy equ 1
|
|
TEST_strcat equ 1
|
|
TEST_strclr equ 1
|
|
TEST_islower equ 1
|
|
TEST_isupper equ 1
|
|
TEST_tolower equ 1
|
|
TEST_toupper equ 1
|
|
TEST_strcmp equ 1
|
|
TEST_min equ 0 ;includes minu
|
|
TEST_max equ 0 ;includes maxu
|
|
TEST_clamp equ 1 ;includes clampu
|
|
|
|
str1 db "Hello, world!",EOS
|
|
str2 db "Hello, World!",EOS
|
|
str3 db "Hello world!",EOS
|
|
str4 db "Howdy environment!",EOS
|
|
str5 db "The quick brown fox jumps over the lazy dog",EOS
|
|
msgStrings db "PRINT str1-5:",NL,"str1: %s",NL,"str2: %s",NL,"str3: %s",NL,"str4: %s",NL,"str5: %s",NL,EOS
|
|
|
|
; print()
|
|
msgPrint db NL,"TEST print()",NL,EOS
|
|
|
|
; puts()
|
|
msgPuts db NL,"TEST puts()",EOS
|
|
|
|
; itoa() / utoa9)
|
|
msgItoa db NL,"TEST itoa() / utoa()",NL,TAB,"See printf outputs",NL,EOS
|
|
|
|
; printf()
|
|
msgPrintf db NL,"TEST printf()",NL,EOS
|
|
printf1 db TAB,"printf(",DQUO,"He%ll%o there%%%%%!%!%\n",DQUO,"): ",NL,TAB,TAB,EOS
|
|
printf1Str db "He%ll%o there%%%%%!%!%",NL,EOS
|
|
printf2 db TAB,"printf(",DQUO,"Are %s doing %s?\n",DQUO,", printf2Str1, printf2Str2): ",NL,TAB,TAB,EOS
|
|
printf2Str db "Are %s doing %s?",NL,EOS
|
|
printf2Str1 db "you",EOS
|
|
printf2Str2 db "okay",EOS
|
|
printf3 db TAB,"printf(",DQUO,"%c%c%c%c%c there %c%c %s%c\n",DQUO,", 'H', 'e', 'l', 'l', 'o', 'm', 'y', ",DQUO,"friend",DQUO,", '!'): ",NL,TAB,TAB,EOS
|
|
printf3Str db "%c%c%c%c%c there %c%c %s%c",NL,EOS
|
|
printf3C1 equ 'H'
|
|
printf3C2 equ 'e'
|
|
printf3C3 equ 'l'
|
|
printf3C4 equ 'l'
|
|
printf3C5 equ 'o'
|
|
printf3C6 equ 'm'
|
|
printf3C7 equ 'y'
|
|
printf3Str1 db "friend",EOS
|
|
printf3C8 equ '!'
|
|
printf4 db TAB,"printf(",DQUO,"%i|%d|%u , %i|%d|%u\n",DQUO,", -50, -50, -50, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF): ",NL,TAB,TAB,EOS
|
|
printf4Str db "%i|%d|%u , %i|%d|%u",NL,EOS
|
|
printf5 db TAB,"printf(",DQUO,"%x|%X , %x|%X\n",DQUO,", 0xabcdeffedcba, 0x069bc0e, 666, -1): ",NL,TAB,TAB,EOS
|
|
printf5Str db "%x|%X , %x|%X",NL,EOS
|
|
printf6 db TAB,"printf(",DQUO,"%b | %8b | %08b\n",DQUO,", 5, 7, 9): ",NL,TAB,TAB,EOS
|
|
printf6Str db "%b | %8b | %08b",NL,EOS
|
|
printf7 db TAB,"printf(",DQUO,"%d | %8d | %08d\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS
|
|
printf7Str db "%d | %8d | %08d",NL,EOS
|
|
printf8 db TAB,"printf(",DQUO,"%i | %8i | %08i\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS
|
|
printf8Str db "%i | %8i | %08i",NL,EOS
|
|
printf9 db TAB,"printf(",DQUO,"%u | %8u | %08u\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS
|
|
printf9Str db "%u | %8u | %08u",NL,EOS
|
|
printf10 db TAB,"printf(",DQUO,"%x | %8x | %08x\n",DQUO,", 0xAB0F, 0xBA0F, 0xAB0F): ",NL,TAB,TAB,EOS
|
|
printf10Str db "%x | %8x | %08x",NL,EOS
|
|
printf11 db TAB,"printf(",DQUO,"%X | %8X | %08X\n",DQUO,", 0xAB0F, 0xBA0F, 0xAB0F): ",NL,TAB,TAB,EOS
|
|
printf11Str db "%X | %8X | %08X",NL,EOS
|
|
printf12 db TAB,"rax=0x1234567890ABCDEF",NL,TAB,"printf(",DQUO,"\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",DQUO,", rax, eax, ax, ah, al): ",NL,TAB,TAB,EOS
|
|
printf12Str db "\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",EOS
|
|
printf13 db TAB,"printf(",DQUO,"%o | %8o | %08o\n",DQUO,", 1500, 1500, 1500): ",NL,TAB,TAB,EOS
|
|
printf13Str db "%o | %8o | %08o\n",EOS
|
|
printf14 db TAB,"printf(",DQUO,"%#b | %#08b | %#x | %#8X | %#o\n",DQUO,", 8, 8, 0xABCDEF, 0x12345678, 15): ",NL,TAB,TAB,EOS
|
|
printf14Str db "%#b | %#08b | %#x | %#8X | %#o\n",EOS
|
|
printf15 db TAB,"printf(",DQUO,"%p | %#p | %8p | %#8p | %08p | %#08p\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS
|
|
printf15Str db "%p | %#p | %8p | %#8p | %08p | %#08p\n",EOS
|
|
printf16 db TAB,"printf(",DQUO,"%x | %#10x | %10x | %#10x | %010x | %#010x\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS
|
|
printf16Str db "%x | %#10x | %10x | %#10x | %010x | %#010x\n",EOS
|
|
; strlen()
|
|
msgStrlen db NL,"TEST strlen()",NL,EOS
|
|
strlen1 db TAB,"strlen(str1): %d",NL,EOS
|
|
strlen2 db TAB,"strlen(str3): %d",NL,EOS
|
|
strlen3 db TAB,"strlen(str5): %d",NL,EOS
|
|
|
|
; strcpy()
|
|
msgStrcpy db NL,"TEST strcpy()",NL,EOS
|
|
strcpy1 db TAB,"strcpy(strBuff1, str1, 12): ",NL,TAB,TAB,EOS
|
|
strcpy2 db TAB,"strcpy(strBuff1, str1, 13): ",NL,TAB,TAB,EOS
|
|
strcpy3 db TAB,"strcpy(strBuff1, str1, 32): ",NL,TAB,TAB,EOS
|
|
strcpy4 db TAB,"strcpy(strBuff1, str5, 32): ",NL,TAB,TAB,EOS
|
|
|
|
; strcat()
|
|
msgStrcat db NL,"TEST strcat()",NL,EOS
|
|
strcat1 db TAB,"strcat(strBuff2, str1, 32): ",NL,TAB,TAB,EOS
|
|
strcat2 db TAB,"strcat(strBuff2, str5, 32): ",NL,TAB,TAB,EOS
|
|
|
|
;strclr()
|
|
msgStrclr db NL,"TEST strclr()",NL,EOS
|
|
strclr1a db TAB,"strcat(strBuff1, str5, 32)",NL,TAB,"strclr(strBuff1, 32)",NL,TAB,"print(strBuff1): ",NL,TAB,TAB,EOS
|
|
strclr1b db TAB,"print(strBuff1[3]): ",NL,TAB,TAB,EOS
|
|
strclr2 db TAB,"strcat(strBuff1, str5, 32)",NL,TAB,"strclr(strbuff1, 2)",NL,TAB,"print(strbuff1[3]): ",NL,TAB,TAB,EOS
|
|
|
|
; islower()
|
|
msgIslower db NL,"TEST islower()",NL,EOS
|
|
islower1 db TAB,"islower(str1[0]): %d",NL,EOS
|
|
islower2 db TAB,"islower(str1[1]): %d",NL,EOS
|
|
islower3 db TAB,"islower('d'): %d",NL,EOS
|
|
islower4 db TAB,"islower('D'): %d",NL,EOS
|
|
islower5 db TAB,"islower('!'): %d",NL,EOS
|
|
|
|
; isupper()
|
|
msgIsupper db NL,"TEST isupper()",NL,EOS
|
|
isupper1 db TAB,"isupper(str1[0]): %d",NL,EOS
|
|
isupper2 db TAB,"isupper(str1[1]): %d",NL,EOS
|
|
isupper3 db TAB,"isupper('d'): %d",NL,EOS
|
|
isupper4 db TAB,"isupper('D'): %d",NL,EOS
|
|
isupper5 db TAB,"isupper('!'): %d",NL,EOS
|
|
|
|
; tolower()
|
|
msgTolower db NL,"TEST tolower()",NL,EOS
|
|
tolower1 db TAB,"tolower(str1[0]): %c",NL,EOS
|
|
tolower2 db TAB,"tolower(str1[1]): %c",NL,EOS
|
|
tolower3 db TAB,"tolower('!'): %c",NL,EOS
|
|
tolower4 db TAB,"tolower() -- entire str4: %s",NL,EOS
|
|
|
|
; toupper()
|
|
msgToupper db NL,"TEST tolower()",NL,EOS
|
|
toupper1 db TAB,"toupper(str1[0]): %c",NL,EOS
|
|
toupper2 db TAB,"toupper(str1[1]): %c",NL,EOS
|
|
toupper3 db TAB,"toupper('!'): %c",NL,EOS
|
|
toupper4 db TAB,"toupper() -- entire str4: %s",NL,EOS
|
|
|
|
; strcmp()
|
|
msgStrcmp db NL,"TEST strcmp()",NL,EOS
|
|
strcmp1 db TAB,"strcmp(str1, str1): %d",NL,EOS
|
|
strcmp2 db TAB,"strcmp(str1, str2): %d",NL,EOS
|
|
strcmp3 db TAB,"- strcpy(strBuff1, str1)",NL,TAB,"- strcat(strBuff1, str2)",NL,TAB,"> strBuff1: %s",NL,TAB,"> str1: %s",NL,TAB,"strcmp(str1, strBuff1): %d",NL,EOS
|
|
strcmp4 db TAB,"strcmp(strBuff1, str1): %d",NL,EOS
|
|
strcmp5 db TAB,"- strclr(strBuff1, 32)",NL,TAB,"strcmp(strBuff1, str1): %d",NL,TAB,"strcmp(str1, strBuff1): %d",NL,EOS
|
|
strcmp6 db TAB,"strcmp(str1, str5): %d",NL,EOS
|
|
|
|
; min() / minu()
|
|
msgMin db NL,"TEST min(), minu()",NL,EOS
|
|
min1 db TAB,"min(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
min2 db TAB,"min(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
min3 db TAB,"min(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
min4 db TAB,"min(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
minu1 db TAB,"minu(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
minu2 db TAB,"minu(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
minu3 db TAB,"minu(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
minu4 db TAB,"minu(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
|
|
; max() / maxu()
|
|
msgMax db NL,"TEST max(), maxu()",NL,EOS
|
|
max1 db TAB,"max(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
max2 db TAB,"max(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
max3 db TAB,"max(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
max4 db TAB,"max(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
maxu1 db TAB,"maxu(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
maxu2 db TAB,"maxu(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
maxu3 db TAB,"maxu(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
maxu4 db TAB,"maxu(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS
|
|
|
|
; clamp() / clampu()
|
|
msgClamp db NL,"clampArg1 = MIN_INT32, clampArg2 = MAX_INT32",NL,"clampuArg1 = MIN_UINT32, clampuArg2 = MAX_UINT32",NL,"TEST clamp(), clampu()",NL,EOS
|
|
clampArg1 equ MIN_INT32
|
|
clampArg2 equ MAX_INT32
|
|
clamp1 db TAB,"clamp(MIN_INT64, clampArg1, clampArg2): %d",NL,EOS
|
|
clamp2 db TAB,"clamp(MAX_INT64, clampArg1, clampArg2): %d",NL,EOS
|
|
clamp3 db TAB,"clamp(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS
|
|
clamp4 db TAB,"clamp(MAX_INT32+1, clampArg1, clampArg2): %d",NL,EOS
|
|
clampuArg1 equ MIN_UINT32
|
|
clampuArg2 equ MAX_UINT32
|
|
clampu1 db TAB,"clampu(MAX_UINT64, clampArg1, clampArg2): %d",NL,EOS
|
|
clampu2 db TAB,"clampu(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS
|
|
section .data
|
|
|
|
section .bss
|
|
strBuff1 resb 32
|
|
strBuff2 resb 32
|
|
|
|
section .text
|
|
global _start
|
|
_start:
|
|
push rbp
|
|
mov rbp, rsp
|
|
sub rsp, SIZE_QWORD
|
|
|
|
; PRINT STRINGS
|
|
lea rdi, [rel msgStrings]
|
|
lea rsi, [rel str1]
|
|
lea rdx, [rel str2]
|
|
lea rcx, [rel str3]
|
|
lea r8, [rel str4]
|
|
lea r9, [rel str5]
|
|
call printf
|
|
|
|
;---
|
|
;--- print()
|
|
;---
|
|
%if TEST_print
|
|
lea rdi, [rel msgPrint]
|
|
call print
|
|
%endif
|
|
|
|
;---
|
|
;--- puts()
|
|
;---
|
|
%if TEST_puts
|
|
lea rdi, [rel msgPuts]
|
|
call puts
|
|
%endif
|
|
|
|
%if TEST_itoa
|
|
lea rdi, [rel msgItoa]
|
|
call print
|
|
%endif
|
|
|
|
;---
|
|
;--- printf()
|
|
;---
|
|
%if TEST_printf
|
|
lea rdi, [rel msgPrintf]
|
|
call printf
|
|
|
|
; TEST 1
|
|
lea rdi, [rel printf1]
|
|
call print
|
|
lea rdi, [rel printf1Str]
|
|
call printf
|
|
|
|
; TEST 2
|
|
lea rdi, [rel printf2]
|
|
call print
|
|
lea rdi, [rel printf2Str]
|
|
lea rsi, [rel printf2Str1]
|
|
lea rdx, [rel printf2Str2]
|
|
call printf
|
|
|
|
; TEST 3
|
|
lea rdi, [rel printf3]
|
|
call print
|
|
lea rdi, [rel printf3Str]
|
|
mov rsi, printf3C1
|
|
mov rdx, printf3C2
|
|
mov rcx, printf3C3
|
|
mov r8, printf3C4
|
|
mov r9, printf3C5
|
|
push printf3C8
|
|
push printf3Str1
|
|
push printf3C7
|
|
push printf3C6
|
|
call printf
|
|
add rsp, SIZE_QWORD * 4
|
|
|
|
; TEST 4
|
|
lea rdi, [rel printf4]
|
|
call print
|
|
lea rdi, [rel printf4Str]
|
|
mov rsi, -50
|
|
mov rdx, -50
|
|
mov rcx, -50
|
|
mov r8, 0xFFFFFFFFFFFFFFFF
|
|
mov r9, 0xFFFFFFFFFFFFFFFF
|
|
sub rsp, SIZE_QWORD
|
|
push 0xFFFFFFFFFFFFFFFF
|
|
call printf
|
|
add rsp, SIZE_QWORD
|
|
|
|
; TEST 5
|
|
lea rdi, [rel printf5]
|
|
call print
|
|
lea rdi, [rel printf5Str]
|
|
mov rsi, 0xabcdeffedcba
|
|
mov rdx, 0x069bc0e
|
|
mov rcx, 666
|
|
mov r8, -1
|
|
call printf
|
|
|
|
; TEST 6
|
|
lea rdi, [rel printf6]
|
|
call print
|
|
lea rdi, [rel printf6Str]
|
|
mov rsi, 5
|
|
mov rdx, 7
|
|
mov rcx, 9
|
|
call printf
|
|
|
|
; TEST 7
|
|
lea rdi, [rel printf7]
|
|
call print
|
|
lea rdi, [rel printf7Str]
|
|
mov rsi, -234
|
|
mov rdx, -666
|
|
mov rcx, 234
|
|
call printf
|
|
|
|
; TEST 8
|
|
lea rdi, [rel printf8]
|
|
call print
|
|
lea rdi, [rel printf8Str]
|
|
mov rsi, -234
|
|
mov rdx, -666
|
|
mov rcx, 234
|
|
call printf
|
|
|
|
; TEST 9
|
|
lea rdi, [rel printf9]
|
|
call print
|
|
lea rdi, [rel printf9Str]
|
|
mov rsi, -234
|
|
mov rdx, -666
|
|
mov rcx, 234
|
|
call printf
|
|
|
|
; TEST 10
|
|
lea rdi, [rel printf10]
|
|
call print
|
|
lea rdi, [rel printf10Str]
|
|
mov rsi, 0xAB0F
|
|
mov rdx, 0xBA0F
|
|
mov rcx, 0xAB0F
|
|
call printf
|
|
|
|
; TEST 11
|
|
lea rdi, [rel printf11]
|
|
call print
|
|
lea rdi, [rel printf11Str]
|
|
mov rsi, 0xAB0F
|
|
mov rdx, 0xBA0F
|
|
mov rcx, 0xAB0F
|
|
call printf
|
|
|
|
; TEST 12
|
|
lea rdi, [rel printf12]
|
|
call print
|
|
|
|
mov rax, 0x1234567890abcdef
|
|
xor rbx, rbx
|
|
xor rcx, rcx
|
|
xor r8, r8
|
|
xor r9, r9
|
|
|
|
lea rdi, [rel printf12Str]
|
|
mov rsi, rax
|
|
mov edx, eax
|
|
mov cx, ax
|
|
mov bh, ah
|
|
mov r8, rbx
|
|
shr r8, 8
|
|
mov r9b, al
|
|
call printf
|
|
|
|
; TEST 13
|
|
lea rdi, [rel printf13]
|
|
call print
|
|
lea rdi, [rel printf13Str]
|
|
mov rsi, 1500
|
|
mov rdx, 1500
|
|
mov rcx, 1500
|
|
call printf
|
|
|
|
; TEST 14
|
|
lea rdi, [rel printf14]
|
|
call print
|
|
lea rdi, [rel printf14Str]
|
|
mov rsi, 8
|
|
mov rdx, 8
|
|
mov rcx, 0xABCDEF
|
|
mov r8, 0x12345678
|
|
mov r9, 15
|
|
call printf
|
|
|
|
; TEST 15
|
|
lea rdi, [rel printf15]
|
|
call print
|
|
lea rdi, [rel printf15Str]
|
|
lea rsi, [rel str5]
|
|
lea rdx, [rel str5]
|
|
lea rcx, [rel str5]
|
|
lea r8, [rel str5]
|
|
lea r9, [rel strBuff1]
|
|
sub rsp, SIZE_QWORD
|
|
push strBuff1
|
|
call printf
|
|
add rsp, SIZE_QWORD * 2
|
|
|
|
; TEST 16
|
|
lea rdi, [rel printf16]
|
|
call print
|
|
lea rdi, [rel printf16Str]
|
|
lea rsi, [rel str5]
|
|
lea rdx, [rel str5]
|
|
lea rcx, [rel str5]
|
|
lea r8, [rel str5]
|
|
lea r9, [rel strBuff1]
|
|
sub rsp, SIZE_QWORD
|
|
push strBuff1
|
|
call printf
|
|
add rsp, SIZE_QWORD * 2
|
|
%endif
|
|
|
|
;---
|
|
;--- strlen()
|
|
;---
|
|
%if TEST_strlen
|
|
lea rdi, [rel msgStrlen]
|
|
call print
|
|
|
|
; TEST 1
|
|
lea rdi, [rel str1]
|
|
call strlen
|
|
lea rdi, [rel strlen1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
lea rdi, [rel str3]
|
|
call strlen
|
|
lea rdi, [rel strlen2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
lea rdi, [rel str5]
|
|
call strlen
|
|
lea rdi, [rel strlen3]
|
|
mov rsi, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- strcpy()
|
|
;---
|
|
%if TEST_strcpy
|
|
lea rdi, [rel msgStrcpy]
|
|
call print
|
|
|
|
; TEST 1
|
|
lea rdi, [rel strcpy1]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
mov rdx, 12
|
|
call strcpy
|
|
mov rdi, rax
|
|
call puts
|
|
; TEST 2
|
|
lea rdi, [rel strcpy2]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
mov rdx, 13
|
|
call strcpy
|
|
mov rdi, rax
|
|
call puts
|
|
; TEST 3
|
|
lea rdi, [rel strcpy3]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
mov rdx, 32
|
|
call strcpy
|
|
mov rdi, rax
|
|
call puts
|
|
; TEST 4
|
|
lea rdi, [rel strcpy4]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str5]
|
|
mov rdx, 32
|
|
call strcpy
|
|
mov rdi, rax
|
|
call puts
|
|
%endif
|
|
|
|
;---
|
|
;--- strcat
|
|
;---
|
|
%if TEST_strcat
|
|
lea rdi, [rel msgStrcat]
|
|
call print
|
|
|
|
; TEST 1
|
|
lea rdi, [rel strcat1]
|
|
call print
|
|
lea rdi, [rel strBuff2]
|
|
lea rsi, [rel str1]
|
|
mov rcx, 32
|
|
call strcat
|
|
mov rdi, rax
|
|
call puts
|
|
|
|
; TEST 3
|
|
lea rdi, [rel strcat2]
|
|
call print
|
|
lea rdi, [rel strBuff2]
|
|
lea rsi, [rel str5]
|
|
mov rcx, 32
|
|
call strcat
|
|
mov rdi, rax
|
|
call puts
|
|
%endif
|
|
|
|
;---
|
|
;--- strclr
|
|
;---
|
|
%if TEST_strclr
|
|
lea rdi, [rel msgStrclr]
|
|
call print
|
|
|
|
; TEST 1
|
|
lea rdi, [rel strclr1a]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str5]
|
|
mov rdx, 32
|
|
call strcat
|
|
lea rdi, [rel strBuff1]
|
|
mov rsi, 32
|
|
call strclr
|
|
lea rdi, [rel strBuff1]
|
|
call puts
|
|
|
|
lea rdi, [rel strclr1b]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
add rdi, 3
|
|
call puts
|
|
|
|
; TEST 2
|
|
lea rdi, [rel strclr2]
|
|
call print
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str5]
|
|
mov rdx, 32
|
|
call strcat
|
|
lea rdi, [rel strBuff1]
|
|
mov rsi, 2
|
|
call strclr
|
|
;lea rdi, [rel strBuff1] ;will add output for this later < works as expected tho
|
|
;call puts
|
|
lea rdi, [rel strBuff1]
|
|
add rdi, 3
|
|
call puts
|
|
%endif
|
|
|
|
;---
|
|
;--- islower()
|
|
;---
|
|
%if TEST_islower
|
|
lea rdi, [rel msgIslower]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov dil, byte [str1]
|
|
call islower
|
|
lea rdi, [rel islower1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov dil, byte [str1 + 1]
|
|
call islower
|
|
lea rdi, [rel islower2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov dil, 'd'
|
|
call islower
|
|
lea rdi, [rel islower3]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov dil, 'D'
|
|
call islower
|
|
lea rdi, [rel islower4]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 5
|
|
mov dil, '!'
|
|
call islower
|
|
lea rdi, [rel islower5]
|
|
mov rsi, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- isupper()
|
|
;---
|
|
%if TEST_isupper
|
|
lea rdi, [rel msgIsupper]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov dil, byte [str1]
|
|
call isupper
|
|
lea rdi, [rel isupper1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov dil, byte [str1 + 1]
|
|
call isupper
|
|
lea rdi, [rel isupper2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov dil, 'd'
|
|
call isupper
|
|
lea rdi, [rel isupper3]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov dil, 'D'
|
|
call isupper
|
|
lea rdi, [rel isupper4]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 5
|
|
mov dil, '!'
|
|
call isupper
|
|
lea rdi, [rel isupper5]
|
|
mov rsi, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- tolower()
|
|
;---
|
|
%if TEST_tolower
|
|
lea rdi, [rel msgTolower]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov dil, byte [str1]
|
|
call tolower
|
|
lea rdi, [rel tolower1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov dil, byte [str1 + 1]
|
|
call tolower
|
|
lea rdi, [rel tolower2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov dil, '!'
|
|
call tolower
|
|
lea rdi, [rel tolower3]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str4]
|
|
mov rdx, 32
|
|
call strcpy
|
|
mov rdi, rax
|
|
call strlen
|
|
mov rcx, rax
|
|
lea rsi, [rel strBuff1]
|
|
.tolowerLoop:
|
|
mov dil, byte [rsi]
|
|
call tolower
|
|
mov byte [rsi], al
|
|
inc rsi
|
|
loop .tolowerLoop
|
|
lea rdi, [rel tolower4]
|
|
lea rsi, [rel strBuff1]
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- toupper()
|
|
;---
|
|
%if TEST_toupper
|
|
lea rdi, [rel msgToupper]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov dil, byte [str1]
|
|
call toupper
|
|
lea rdi, [rel toupper1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov dil, byte [str1 + 1]
|
|
call toupper
|
|
lea rdi, [rel toupper2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov dil, '!'
|
|
call toupper
|
|
lea rdi, [rel toupper3]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str4]
|
|
mov rdx, 32
|
|
call strcpy
|
|
mov rdi, rax
|
|
call strlen
|
|
mov rcx, rax
|
|
lea rsi, [rel strBuff1]
|
|
.toupperLoop:
|
|
mov dil, byte [rsi]
|
|
call toupper
|
|
mov byte [rsi], al
|
|
inc rsi
|
|
loop .toupperLoop
|
|
lea rdi, [rel toupper4]
|
|
lea rsi, [rel strBuff1]
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- strcmp()
|
|
;---
|
|
%if TEST_strcmp
|
|
lea rdi, [rel msgStrcmp]
|
|
call printf
|
|
|
|
; TEST 1
|
|
lea rdi, [rel str1]
|
|
lea rsi, [rel str1]
|
|
call strcmp
|
|
lea rdi, [rel strcmp1]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
lea rdi, [rel str1]
|
|
lea rsi, [rel str2]
|
|
call strcmp
|
|
lea rdi, [rel strcmp2]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
call strcpy
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str2]
|
|
call strcat
|
|
lea rdi, [rel str1]
|
|
lea rsi, [rel strBuff1]
|
|
call strcmp
|
|
lea rdi, [rel strcmp3]
|
|
lea rsi, [rel strBuff1]
|
|
lea rdx, [rel str1]
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
call strcmp
|
|
lea rdi, [rel strcmp4]
|
|
mov rsi, rax
|
|
call printf
|
|
|
|
; TEST 5
|
|
lea rdi, [rel strBuff1]
|
|
mov rsi, 32
|
|
call strclr
|
|
lea rdi, [rel strBuff1]
|
|
lea rsi, [rel str1]
|
|
call strcmp
|
|
mov rbx, rax
|
|
lea rdi, [rel str1]
|
|
lea rsi, [rel strBuff1]
|
|
call strcmp
|
|
lea rdi, [rel strcmp5]
|
|
mov rsi, rbx
|
|
mov rdx, rax
|
|
call printf
|
|
|
|
; TEST 6
|
|
|
|
lea rdi, [rel str1]
|
|
lea rsi, [rel str5]
|
|
call strcmp
|
|
lea rdi, [rel strcmp6]
|
|
mov rsi, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- min() / minu()
|
|
;---
|
|
%if TEST_min
|
|
lea rdi, [rel msgMin]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov rdi, 15
|
|
mov rsi, 30
|
|
call min
|
|
lea rdi, [rel min1]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov rdi, -15
|
|
mov rsi, -30
|
|
call min
|
|
lea rdi, [rel min2]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov rdi, -1
|
|
xor rsi, rsi
|
|
call min
|
|
lea rdi, [rel min3]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov rdi, 0xFFFFFFFF
|
|
mov rsi, -4294967295
|
|
call min
|
|
lea rdi, [rel min4]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 1
|
|
mov rdi, 15
|
|
mov rsi, 30
|
|
call minu
|
|
lea rdi, [rel minu1]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov rdi, -15
|
|
mov rsi, -30
|
|
call minu
|
|
lea rdi, [rel minu2]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov rdi, -1
|
|
xor rsi, rsi
|
|
call minu
|
|
lea rdi, [rel minu3]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov rdi, 0xFFFFFFFF
|
|
mov rsi, -4294967295
|
|
call minu
|
|
lea rdi, [rel minu4]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- max() / maxu()
|
|
;---
|
|
%if TEST_max
|
|
lea rdi, [rel msgMin]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov rdi, 15
|
|
mov rsi, 30
|
|
call max
|
|
lea rdi, [rel max1]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov rdi, -15
|
|
mov rsi, -30
|
|
call max
|
|
lea rdi, [rel max2]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov rdi, -1
|
|
xor rsi, rsi
|
|
call max
|
|
lea rdi, [rel max3]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov rdi, 0xFFFFFFFF
|
|
mov rsi, -4294967295
|
|
call max
|
|
lea rdi, [rel max4]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 1
|
|
mov rdi, 15
|
|
mov rsi, 30
|
|
call maxu
|
|
lea rdi, [rel maxu1]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 2
|
|
mov rdi, -15
|
|
mov rsi, -30
|
|
call maxu
|
|
lea rdi, [rel maxu2]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 3
|
|
mov rdi, -1
|
|
xor rsi, rsi
|
|
call maxu
|
|
lea rdi, [rel maxu3]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
|
|
; TEST 4
|
|
mov rdi, 0xFFFFFFFF
|
|
mov rsi, -4294967295
|
|
call maxu
|
|
lea rdi, [rel maxu4]
|
|
mov rsi, rax
|
|
mov rdx, rax
|
|
mov rcx, rax
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- clamp() / clampu()
|
|
;---
|
|
%if TEST_clamp
|
|
lea rdi, [rel msgClamp]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov rdi, MIN_INT64
|
|
mov rsi, clampArg1
|
|
mov rdx, clampArg2
|
|
call clamp
|
|
mov rsi, rax
|
|
lea rdi, [rel clamp1]
|
|
call printf
|
|
; TEST 2
|
|
mov rdi, MAX_INT64
|
|
mov rsi, clampArg1
|
|
mov rdx, clampArg2
|
|
call clamp
|
|
mov rsi, rax
|
|
lea rdi, [rel clamp2]
|
|
call printf
|
|
; TEST 3
|
|
mov rdi, MAX_UINT16
|
|
mov rsi, clampArg1
|
|
mov rdx, clampArg2
|
|
call clamp
|
|
mov rsi, rax
|
|
lea rdi, [rel clamp3]
|
|
call printf
|
|
; TEST 4
|
|
mov rdi, MAX_INT32+1
|
|
mov rsi, clampArg1
|
|
mov rdx, clampArg2
|
|
call clamp
|
|
mov rsi, rax
|
|
lea rdi, [rel clamp4]
|
|
call printf
|
|
|
|
; TEST 5
|
|
mov rdi, MAX_UINT64
|
|
mov rsi, clampuArg1
|
|
mov rdx, clampuArg2
|
|
call clampu
|
|
mov rsi, rax
|
|
lea rdi, [rel clampu1]
|
|
call printf
|
|
|
|
; TEST 6
|
|
mov rdi, MAX_UINT16
|
|
mov rsi, clampuArg1
|
|
mov rdx, clampuArg2
|
|
call clampu
|
|
mov rsi, rax
|
|
lea rdi, [rel clampu2]
|
|
call printf
|
|
%endif
|
|
|
|
;---
|
|
;--- exit()
|
|
;---
|
|
leave
|
|
mov rdi, 0
|
|
call exit
|