Compare commits
2 commits
e40f7dbe2b
...
0428078991
Author | SHA1 | Date | |
---|---|---|---|
0428078991 | |||
33a00bf2c2 |
4 changed files with 91 additions and 2 deletions
|
@ -18,6 +18,6 @@ add_compile_options(-g)
|
||||||
add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
|
add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
|
||||||
|
|
||||||
#Make a EXE with cpp and asm files
|
#Make a EXE with cpp and asm files
|
||||||
add_library(z tolower.asm strlen.asm strcmp.asm atoi.asm hextoi.asm)
|
add_library(z tolower.asm strlen.asm strcmp.asm atoi.asm)
|
||||||
add_executable(example example.asm)
|
add_executable(example example.asm)
|
||||||
target_link_libraries(example z)
|
target_link_libraries(example z)
|
||||||
|
|
24
example.asm
24
example.asm
|
@ -3,6 +3,7 @@ extern libz_strlen
|
||||||
extern libz_strcmp
|
extern libz_strcmp
|
||||||
extern libz_tolower
|
extern libz_tolower
|
||||||
extern libz_atoi
|
extern libz_atoi
|
||||||
|
extern malloc
|
||||||
|
|
||||||
section .data
|
section .data
|
||||||
text2 db "asdasdASDd",0
|
text2 db "asdasdASDd",0
|
||||||
|
@ -60,7 +61,7 @@ _differ:
|
||||||
mov rdi, differ
|
mov rdi, differ
|
||||||
cld
|
cld
|
||||||
call puts
|
call puts
|
||||||
jmp _end
|
jmp _afterdiff
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,6 +70,27 @@ _notdiffer:
|
||||||
cld
|
cld
|
||||||
call puts
|
call puts
|
||||||
|
|
||||||
|
_afterdiff:
|
||||||
|
|
||||||
|
mov rdi, 20
|
||||||
|
cld
|
||||||
|
call malloc
|
||||||
|
;i think i just malloced (hopefully)
|
||||||
|
|
||||||
|
xor rcx, rcx
|
||||||
|
_malloctestloop:
|
||||||
|
mov [rax], rcx
|
||||||
|
cmp rcx, 20
|
||||||
|
je _end
|
||||||
|
inc rcx
|
||||||
|
inc rax
|
||||||
|
jmp _malloctestloop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
add rsp, 8 ;exit
|
add rsp, 8 ;exit
|
||||||
ret
|
ret
|
||||||
|
|
29
tolower.asm
29
tolower.asm
|
@ -1,4 +1,5 @@
|
||||||
extern libz_strlen
|
extern libz_strlen
|
||||||
|
extern malloc
|
||||||
|
|
||||||
global libz_tolower
|
global libz_tolower
|
||||||
section .text
|
section .text
|
||||||
|
@ -11,6 +12,32 @@ libz_tolower:
|
||||||
call libz_strlen
|
call libz_strlen
|
||||||
mov r10, rax
|
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
|
xor rcx, rcx ;we do this to clear rcx incase it had garbage in it before
|
||||||
_loop:
|
_loop:
|
||||||
|
@ -34,5 +61,7 @@ _endloop:
|
||||||
cmp rcx, r10
|
cmp rcx, r10
|
||||||
jle _loop
|
jle _loop
|
||||||
|
|
||||||
|
pop rax ;returning rax (the pointer to the new string)
|
||||||
|
|
||||||
add rsp, 8 ;exit
|
add rsp, 8 ;exit
|
||||||
ret
|
ret
|
||||||
|
|
38
tolower_legacy.asm
Normal file
38
tolower_legacy.asm
Normal file
|
@ -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
|
Loading…
Reference in a new issue