From 0428078991057ebf2be8ef4c84094ee33a548468 Mon Sep 17 00:00:00 2001 From: zombie Date: Sat, 27 Nov 2021 04:39:20 -0500 Subject: [PATCH] made tolower not nuke your string (i think) previously tolower would take your string and modify it but now it returns a new string that has been tolowered --- tolower.asm | 29 +++++++++++++++++++++++++++++ tolower_legacy.asm | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tolower_legacy.asm diff --git a/tolower.asm b/tolower.asm index add19b3..c35e789 100644 --- a/tolower.asm +++ b/tolower.asm @@ -1,4 +1,5 @@ extern libz_strlen +extern malloc global libz_tolower section .text @@ -11,6 +12,32 @@ libz_tolower: 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: @@ -34,5 +61,7 @@ _endloop: cmp rcx, r10 jle _loop + pop rax ;returning rax (the pointer to the new string) + add rsp, 8 ;exit ret diff --git a/tolower_legacy.asm b/tolower_legacy.asm new file mode 100644 index 0000000..add19b3 --- /dev/null +++ b/tolower_legacy.asm @@ -0,0 +1,38 @@ +extern libz_strlen + +global libz_tolower +section .text + +libz_tolower: + sub rsp, 8 ;enter + + mov r11, rdi + + call libz_strlen + mov r10, rax + + + 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 + + add rsp, 8 ;exit + ret