Created
September 10, 2016 07:34
-
-
Save carld/ee6015d56c80298080f85fcbba1dc4c1 to your computer and use it in GitHub Desktop.
string equals in x86_64 nasm assembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .text | |
global start | |
start: | |
mov rsi, s1 ; esi = &s1 | |
mov rdi, s2 ; edi = &s2 | |
xor rdx, rdx ; edx = 0 | |
loop: | |
mov al, [rsi + rdx] | |
mov bl, [rdi + rdx] | |
inc rdx | |
cmp al, bl ; compare two current characters | |
jne not_equal ; not equal | |
cmp al, 0 ; at end? | |
je equal ; end of both strings | |
jmp loop ; equal so far | |
not_equal: | |
mov rdi, 1 | |
jmp exit | |
equal: | |
mov rdi, 0 | |
jmp exit | |
exit: | |
mov rax, 0x2000001 ; sys_exit | |
; mov rdi, 0 | |
syscall | |
section .data | |
s1: db "string one", 0 | |
s2: db "string on1", 0 |
0x4ka5h
commented
Apr 21, 2021
This code has an error at line 23. mov rax, 0x2000001
will raise segmentation fault (core dump). Use mov rax, 60
instead. 60 is the code of the system call SYS_EXIT.
This code has an error at line 23.
mov rax, 0x2000001
will raise segmentation fault (core dump). Usemov rax, 60
instead. 60 is the code of the system call SYS_EXIT.
mov rax, 0x2000001
is the syscall for exit in assembly on macos.
You can also use the cmps
instruction.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment