936 lines
17 KiB
NASM
936 lines
17 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 dec2str
|
|
extern udec2str
|
|
extern hex2str
|
|
extern bin2str
|
|
|
|
section .rodata
|
|
TEST_print equ 1
|
|
TEST_puts equ 1
|
|
TEST_dec2str equ 1 ;includes udec2str
|
|
TEST_hex2str equ 1
|
|
TEST_bin2str equ 1
|
|
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 1 ;includes minu
|
|
TEST_max equ 1 ;includes maxu
|
|
|
|
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
|
|
|
|
; START LAZY SECTION
|
|
; [u]dec2str() / hex2str() / bin2str()
|
|
msgDec2str db NL,"TEST dec2str() / udec2str()",NL,TAB,"Use GDB ('x/s $rax' after function call)",NL,TAB,"No tests printed - see printf outputs :)",NL,EOS
|
|
msgHex2str db NL,"TEST hex2str()",NL,TAB,"Use GDB ('x/s $rax' after function call)",NL,TAB,"No tests printed - see printf outputs :)",NL,EOS
|
|
msgBin2str db NL,"TEST bin2str()",NL,TAB,"See min/max tests",NL,EOS ;Even more lazy
|
|
; END LAZY SECTION
|
|
|
|
; 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,"): ",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, 5, 5): ",NL,TAB,TAB,EOS
|
|
printf6Str db "%b | %8b | %08b",NL,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
|
|
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
|
|
|
|
;---
|
|
;--- dec2str() / udec2str()
|
|
;---
|
|
%if TEST_dec2str
|
|
lea rdi, [rel msgDec2str]
|
|
call print
|
|
|
|
; TEST 1
|
|
mov rdi, -569384
|
|
call dec2str
|
|
; TEST 2
|
|
mov rdi, -569384
|
|
call udec2str
|
|
; TEST 3
|
|
mov rdi, 0xFFFFFFFFFFFFFFFF
|
|
call dec2str
|
|
; TEST 4
|
|
mov rdi, 0xFFFFFFFFFFFFFFFF
|
|
call udec2str
|
|
%endif
|
|
|
|
;---
|
|
;--- hex2str()
|
|
;---
|
|
%if TEST_hex2str
|
|
lea rdi, [rel msgHex2str]
|
|
call print
|
|
|
|
; TEST 1
|
|
xor rdi, rdi
|
|
mov rsi, 0
|
|
call hex2str
|
|
mov rdi, -1
|
|
mov rsi, 0
|
|
call hex2str
|
|
|
|
; TEST 2
|
|
xor rdi, rdi
|
|
mov rsi, 1
|
|
call hex2str
|
|
mov rdi, -1
|
|
mov rsi, 1
|
|
call hex2str
|
|
|
|
; TEST 3
|
|
mov rdi, 0x123456789ABCDEF
|
|
mov rsi, 0
|
|
call hex2str
|
|
mov rdi, 0x123456789ABCDEF
|
|
mov rsi, 1
|
|
call hex2str
|
|
|
|
; TEST 4
|
|
mov rdi, 128
|
|
mov rsi, 0
|
|
call hex2str
|
|
%endif
|
|
|
|
;---
|
|
;--- bin2str()
|
|
;---
|
|
%if TEST_bin2str
|
|
lea rdi, [rel msgBin2str]
|
|
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, 5
|
|
mov rcx, 5
|
|
call printf
|
|
%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
|
|
|
|
;---
|
|
;--- exit()
|
|
;---
|
|
leave
|
|
mov rdi, 0
|
|
call exit
|