length finally fucking works

This commit is contained in:
zombie maniac 2021-09-18 05:43:26 -04:00
parent e63923d4a8
commit bc103e75bd
3 changed files with 6 additions and 12 deletions

View file

@ -20,4 +20,3 @@ add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
add_executable(length length.asm) add_executable(length length.asm)
add_executable(yes yes.asm) add_executable(yes yes.asm)
add_executable(case case.asm) add_executable(case case.asm)

View file

@ -10,7 +10,8 @@ section .rodata
format db "%#x", 10, 0 format db "%#x", 10, 0
section .data section .data
text db "rEEEeee!EEeeeEeEEeE!EEEEEeEEE$eeeEE)EEeEeEEeeeEeEEEEEeeeEeeEeeEeeeeeEeEeEeeE",0 text db "rEE",0
testasd dq 0
section .text section .text
global main global main
@ -21,22 +22,20 @@ main:
mov r8, text mov r8, text
call length_func call length_func
mov [testasd], rax
mov rdi, text mov rdi, text
cld cld
call puts ;this is the puts way of printing a string call puts ;this is the puts way of printing a string
mov rsi, r8 mov rsi, [testasd]
lea rdi, [rel format] lea rdi, [rel format]
xor eax, eax ; AL=0 no FP args in XMM regs xor eax, eax ; AL=0 no FP args in XMM regs
call printf call printf
_end: _end:
add rsp, 8 ;exit add rsp, 8 ;exit
ret ret

View file

@ -1,9 +1,9 @@
length_func: length_func:
mov r10, r8
_loop67865432: _loop67865432:
mov r9b, [r8] mov r9b, [r8]
cmp r9b, 0 cmp r9b, 0
jz _exitloop4323567 jz _exitloop4323567
@ -11,11 +11,7 @@ _loop67865432:
jmp _loop67865432 jmp _loop67865432
_exitloop4323567: _exitloop4323567:
dec r8 ; idk how to do it properly do im doing this instead
dec r8
dec r8
dec r8
sub r8, r10
mov rax, r8 mov rax, r8
ret ret