zombie
0428078991
previously tolower would take your string and modify it but now it returns a new string that has been tolowered
67 lines
1.2 KiB
NASM
67 lines
1.2 KiB
NASM
extern libz_strlen
|
|
extern malloc
|
|
|
|
global libz_tolower
|
|
section .text
|
|
|
|
libz_tolower:
|
|
sub rsp, 8 ;enter
|
|
|
|
mov r11, rdi
|
|
|
|
call libz_strlen
|
|
mov r10, rax
|
|
|
|
inc rax ;we do this because we need room for the null terminator
|
|
|
|
mov rdi, rax
|
|
push r11
|
|
push r10
|
|
call malloc ;spot to put the new string
|
|
pop r10
|
|
pop r11
|
|
|
|
;at this point r11 (hopfully) has the original string and rax has the new string home
|
|
push rax ;save rax for later
|
|
push rax ;save it twice so we can return the pointer
|
|
_mcopyloop:
|
|
mov r8b, [r11]
|
|
mov [rax], r8b
|
|
inc r11
|
|
inc rax
|
|
|
|
mov rsi, [r11] ;man i hope i can use rsi for anything and it wont nuke anything
|
|
cmp sil, 0
|
|
jnz _mcopyloop
|
|
|
|
pop r11 ;the loop below uses r11
|
|
|
|
|
|
|
|
|
|
xor rcx, rcx ;we do this to clear rcx incase it had garbage in it before
|
|
_loop:
|
|
;do loop things
|
|
|
|
mov r9, r11
|
|
add r9, rcx
|
|
|
|
mov r8b, [r9] ;this block here makes sure that our character is a capital letter and if its not a capital letter do nothing and return
|
|
cmp r8b, 90
|
|
ja _endloop
|
|
cmp r8b, 65
|
|
jb _endloop
|
|
|
|
add r8b, 32 ;make the letter capital
|
|
mov [r9], r8b
|
|
|
|
_endloop:
|
|
;end loop
|
|
inc rcx
|
|
cmp rcx, r10
|
|
jle _loop
|
|
|
|
pop rax ;returning rax (the pointer to the new string)
|
|
|
|
add rsp, 8 ;exit
|
|
ret
|