Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Last active November 1, 2016 19:40
Show Gist options
  • Save vendethiel/08068dd076be1fdc90ab23658c4ca803 to your computer and use it in GitHub Desktop.
Save vendethiel/08068dd076be1fdc90ab23658c4ca803 to your computer and use it in GitHub Desktop.
.global _start
.text
# strcmp(rdi=str1, rsi=str2, ecx=length_of_longest): %rax
_start:
pushq %rbp
movq %rsp, %rbp
movabsq $str1, %rdi
movabsq $str2, %rsi
movl $str1_size, %ecx
call strcmp
leave
ret
strcmp:
pushq %rbp
movq %rsp, %rbp
cld
repe cmpsb # compare %rdi[n]==%rsi[n] n=0..%ecx
movl %ecx, %eax
and $1, %eax # make sure result is 0 (eq) or 1 (uneq)
leave
ret
str1:
.asciz "Hello ate"
.set str1_size, .-str1
str2:
.asciz "Hello ate"
.set str2_size, .-str2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment