Test toupper() and tolower() for entire string
This commit is contained in:
65
tests.asm
65
tests.asm
@ -44,7 +44,11 @@ section .rodata
|
|||||||
msgStrcat db "strcat(str1Copy, str3): %s",10,0
|
msgStrcat db "strcat(str1Copy, str3): %s",10,0
|
||||||
msgStrlen3 db "strlen(str1Copy): %d",10,0
|
msgStrlen3 db "strlen(str1Copy): %d",10,0
|
||||||
msgTolower db "tolower(str1[0]): %c",10,0
|
msgTolower db "tolower(str1[0]): %c",10,0
|
||||||
msgToupper db "toupper(str1[1]): %c",10,0
|
msgTolower2 db "tolower(str1[1]): %c",10,0
|
||||||
|
msgTolower3 db "tolower() for whole str1Copy: %s",10,0
|
||||||
|
msgToupper db "toupper(str1[0]): %c",10,0
|
||||||
|
msgToupper2 db "toupper(str1[1]): %c",10,0
|
||||||
|
msgToupper3 db "toupper() for whole str1Copy: %s",10,0
|
||||||
section .data
|
section .data
|
||||||
section .bss
|
section .bss
|
||||||
str1Copy resb 32
|
str1Copy resb 32
|
||||||
@ -205,14 +209,69 @@ main:
|
|||||||
xor rax, rax
|
xor rax, rax
|
||||||
lea rdi, [rel msgTolower]
|
lea rdi, [rel msgTolower]
|
||||||
call printf
|
call printf
|
||||||
|
; ...str1[1]
|
||||||
; TEST: toupper(str1[1])
|
|
||||||
lea rdi, [rel str1+1]
|
lea rdi, [rel str1+1]
|
||||||
|
call tolower
|
||||||
|
mov rsi, rax
|
||||||
|
xor rax, rax
|
||||||
|
lea rdi, [rel msgTolower2]
|
||||||
|
call printf
|
||||||
|
|
||||||
|
; TEST: toupper(str1[0])
|
||||||
|
lea rdi, [rel str1]
|
||||||
call toupper
|
call toupper
|
||||||
mov rsi, rax
|
mov rsi, rax
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
lea rdi, [rel msgToupper]
|
lea rdi, [rel msgToupper]
|
||||||
call printf
|
call printf
|
||||||
|
; ...str1[1]
|
||||||
|
lea rdi, [rel str1+1]
|
||||||
|
call toupper
|
||||||
|
mov rsi, rax
|
||||||
|
xor rax, rax
|
||||||
|
lea rdi, [rel msgToupper2]
|
||||||
|
call printf
|
||||||
|
|
||||||
|
; TEST: tolower: entire str1Copy
|
||||||
|
lea rdi, [rel str1Copy]
|
||||||
|
call strlen
|
||||||
|
mov rcx, rax
|
||||||
|
.tolowerLoop:
|
||||||
|
movzx r10, byte [rdi]
|
||||||
|
mov byte [rdi], r10b
|
||||||
|
push rcx
|
||||||
|
sub rsp, 8
|
||||||
|
call tolower
|
||||||
|
add rsp, 8
|
||||||
|
pop rcx
|
||||||
|
mov byte [rdi], al
|
||||||
|
inc rdi
|
||||||
|
inc r10
|
||||||
|
loop .tolowerLoop
|
||||||
|
xor rax, rax
|
||||||
|
lea rdi, [rel msgTolower3]
|
||||||
|
lea rsi, [rel str1Copy]
|
||||||
|
call printf
|
||||||
|
|
||||||
|
; TEST: toupper: entire str1Copy
|
||||||
|
lea rdi, [rel str1Copy]
|
||||||
|
call strlen
|
||||||
|
mov rcx, rax
|
||||||
|
.toupperLoop:
|
||||||
|
movzx r10, byte [rdi]
|
||||||
|
mov byte [rdi], r10b
|
||||||
|
push rcx
|
||||||
|
sub rsp, 8
|
||||||
|
call toupper
|
||||||
|
add rsp, 8
|
||||||
|
pop rcx
|
||||||
|
mov byte [rdi], al
|
||||||
|
inc rdi
|
||||||
|
inc r10
|
||||||
|
loop .toupperLoop
|
||||||
|
xor rax, rax
|
||||||
|
lea rdi, [rel msgToupper3]
|
||||||
|
lea rsi, [rel str1Copy]
|
||||||
|
call printf
|
||||||
leave
|
leave
|
||||||
ret
|
ret
|
||||||
|
Reference in New Issue
Block a user