Improved strlen test (output), test islower/isupper
This commit is contained in:
170
src/tests.asm
170
src/tests.asm
@@ -2,6 +2,8 @@
|
||||
|
||||
; core.asm
|
||||
extern exit
|
||||
extern islower
|
||||
extern isupper
|
||||
; console.asm
|
||||
extern print
|
||||
extern puts
|
||||
@@ -26,21 +28,28 @@ section .rodata
|
||||
TEST_strcpy equ 1
|
||||
TEST_strcat equ 1
|
||||
TEST_strclr equ 1
|
||||
TEST_islower equ 1
|
||||
TEST_isupper equ 1
|
||||
|
||||
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,NL,EOS
|
||||
|
||||
; print()
|
||||
msgPrint db "TEST print()",NL,EOS
|
||||
msgPrint db NL,"TEST print()",NL,EOS
|
||||
|
||||
; puts()
|
||||
msgPuts db "TEST puts()",EOS
|
||||
msgPuts db NL,"TEST puts()",EOS
|
||||
|
||||
; [u]dec2str() / hex2str()
|
||||
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
|
||||
|
||||
; printf()
|
||||
msgPrintf db "TEST printf()",NL,EOS
|
||||
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
|
||||
@@ -64,27 +73,45 @@ section .rodata
|
||||
printf5Str db "%x|%X , %x|%X",NL,EOS
|
||||
|
||||
; strlen()
|
||||
strlenStr1 db "Hello",EOS
|
||||
strlenStr2 db "Hello, world!",NL,EOS
|
||||
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 "TEST strcpy()",NL,EOS
|
||||
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 "TEST strcat()",NL,EOS
|
||||
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 "TEST strclr()",NL,EOS
|
||||
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
|
||||
|
||||
section .data
|
||||
|
||||
section .bss
|
||||
@@ -98,6 +125,15 @@ _start:
|
||||
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()
|
||||
;---
|
||||
@@ -118,13 +154,19 @@ _start:
|
||||
;--- dec2str() / udec2str()
|
||||
;---
|
||||
%if TEST_dec2str
|
||||
; x/s $rax after calls to confirm proper output
|
||||
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
|
||||
@@ -133,6 +175,9 @@ _start:
|
||||
;--- hex2str()
|
||||
;---
|
||||
%if TEST_hex2str
|
||||
lea rdi, [rel msgHex2str]
|
||||
call print
|
||||
|
||||
; TEST 1
|
||||
xor rdi, rdi
|
||||
mov rsi, 0
|
||||
@@ -229,12 +274,29 @@ _start:
|
||||
;--- strlen()
|
||||
;---
|
||||
%if TEST_strlen
|
||||
lea rdi, [rel msgStrlen]
|
||||
call print
|
||||
|
||||
; TEST 1
|
||||
lea rdi, [rel strlenStr1]
|
||||
lea rdi, [rel str1]
|
||||
call strlen
|
||||
lea rdi, [rel strlen1]
|
||||
mov rsi, rax
|
||||
call printf
|
||||
|
||||
; TEST 2
|
||||
lea rdi, [rel strlenStr2]
|
||||
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
|
||||
|
||||
;---
|
||||
@@ -351,6 +413,92 @@ _start:
|
||||
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
|
||||
|
||||
;---
|
||||
;--- exit()
|
||||
;---
|
||||
|
Reference in New Issue
Block a user