Compare commits
6 commits
e63923d4a8
...
fcaf7f98f7
Author | SHA1 | Date | |
---|---|---|---|
fcaf7f98f7 | |||
093e21db45 | |||
7fecbb5170 | |||
a55d2bd12c | |||
ad76e24e30 | |||
bc103e75bd |
5 changed files with 99 additions and 19 deletions
|
@ -20,4 +20,4 @@ add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
|
|||
add_executable(length length.asm)
|
||||
add_executable(yes yes.asm)
|
||||
add_executable(case case.asm)
|
||||
|
||||
add_executable(diff diff.asm)
|
||||
|
|
7
case.asm
7
case.asm
|
@ -1,14 +1,19 @@
|
|||
extern puts
|
||||
|
||||
%include "../inc/length_func.inc"
|
||||
|
||||
section .data
|
||||
text db "rEEEeee!EEeeeEeEEeE!EEEEEeEEE$eeeEE)EEeEeEEeeeEeEEEEEeeeEeeEeeEeeeeeEeEeEeeE",0
|
||||
textlength db 76
|
||||
textlength db 0
|
||||
section .text
|
||||
global main
|
||||
|
||||
main:
|
||||
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
|
||||
|
|
84
diff.asm
Normal file
84
diff.asm
Normal 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
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
length_func:
|
||||
|
||||
mov r10, r8
|
||||
_loop67865432:
|
||||
|
||||
|
||||
mov r9b, [r8]
|
||||
cmp r9b, 0
|
||||
jz _exitloop4323567
|
||||
|
@ -11,11 +11,7 @@ _loop67865432:
|
|||
|
||||
jmp _loop67865432
|
||||
_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
|
||||
ret
|
17
length.asm
17
length.asm
|
@ -1,16 +1,17 @@
|
|||
extern puts
|
||||
extern printf
|
||||
default rel
|
||||
%include "../length_func.inc"
|
||||
%include "../inc/length_func.inc"
|
||||
|
||||
|
||||
|
||||
|
||||
section .rodata
|
||||
format db "%#x", 10, 0
|
||||
format db "%#d", 10, 0
|
||||
|
||||
section .data
|
||||
text db "rEEEeee!EEeeeEeEEeE!EEEEEeEEE$eeeEE)EEeEeEEeeeEeEEEEEeeeEeeEeeEeeeeeEeEeEeeE",0
|
||||
text db "rEE",0
|
||||
testasd dq 0
|
||||
section .text
|
||||
global main
|
||||
|
||||
|
@ -21,22 +22,16 @@ main:
|
|||
|
||||
mov r8, text
|
||||
call length_func
|
||||
mov [testasd], rax
|
||||
|
||||
|
||||
|
||||
mov rdi, text
|
||||
cld
|
||||
call puts ;this is the puts way of printing a string
|
||||
|
||||
|
||||
mov rsi, r8
|
||||
mov rsi, [testasd]
|
||||
lea rdi, [rel format]
|
||||
xor eax, eax ; AL=0 no FP args in XMM regs
|
||||
call printf
|
||||
|
||||
|
||||
|
||||
|
||||
_end:
|
||||
add rsp, 8 ;exit
|
||||
ret
|
||||
|
|
Loading…
Reference in a new issue