Compare commits

..

6 commits

5 changed files with 99 additions and 19 deletions

View file

@ -20,4 +20,4 @@ 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)
add_executable(diff diff.asm)

View file

@ -1,14 +1,19 @@
extern puts extern puts
%include "../inc/length_func.inc"
section .data section .data
text db "rEEEeee!EEeeeEeEEeE!EEEEEeEEE$eeeEE)EEeEeEEeeeEeEEEEEeeeEeeEeeEeeeeeEeEeEeeE",0 text db "rEEEeee!EEeeeEeEEeE!EEEEEeEEE$eeeEE)EEeEeEEeeeEeEEEEEeeeEeeEeeEeeeeeEeEeEeeE",0
textlength db 76 textlength db 0
section .text section .text
global main global main
main: main:
sub rsp, 8 ;enter sub rsp, 8 ;enter
mov r8, text ;get textlength
call length_func
mov [textlength], rax
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

84
diff.asm Normal file
View file

@ -0,0 +1,84 @@
extern puts
%include "../inc/length_func.inc"
section .data
text db "REEEEEEEEEE",0
text2 db "REEEEEEErEE",0
differ db "they differ",0
notdiffer db "they do not differ",0
textlength dq 0
text2length dq 0
section .text
global main
main:
sub rsp, 8 ;enter
;below we are getting the length of each string
;we do this because we dont want to compare with memory that isnt ours
mov r8, text
call length_func
mov [textlength], rax
mov r8, text2
call length_func
mov [text2length], rax
mov r8, [textlength]
mov r9, [text2length]
cmp r8, r9
jne _differ
xor rcx, rcx ;we do this to clear garbage in rcx (i have had garbage in it before)
_loop:
;loop tings
mov r8, text
add r8, rcx
mov r9, text2
add r9, rcx
mov r10b, [r8]
mov r11b, [r9]
cmp r10b, r11b
jne _differ
cmp r10b, 0
je _notdiffer
cmp r11b, 0
je _notdiffer
inc rcx
jmp _loop
_differ:
mov rdi, differ
cld
call puts
jmp _end
_notdiffer:
mov rdi, notdiffer
cld
call puts
_end:
add rsp, 8 ;exit
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

View file

@ -1,16 +1,17 @@
extern puts extern puts
extern printf extern printf
default rel default rel
%include "../length_func.inc" %include "../inc/length_func.inc"
section .rodata section .rodata
format db "%#x", 10, 0 format db "%#d", 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,16 @@ main:
mov r8, text mov r8, text
call length_func call length_func
mov [testasd], rax
mov rsi, [testasd]
mov rdi, text
cld
call puts ;this is the puts way of printing a string
mov rsi, r8
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