diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/strcmp.s | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/strcmp.s b/src/lib/strcmp.s new file mode 100644 index 0000000..7e6d2af --- /dev/null +++ b/src/lib/strcmp.s @@ -0,0 +1,34 @@ +# -------------------------------------------- +# FUNCTION: strcmp +# PURPOSE : compares twos strings, and returns +# if they are equal +# INPUTS : rdi = address of first string +# rsi = address of second string +# OUTPUTS : rax = 1 if equals else 0 +# CLOBBERS: +# -------------------------------------------- +.section .text +.globl strcmp +.type strcmp, @function +strcmp: + xorq %rax, %rax # i = 0 + movb (%rdi, %rax, 1), %r8b + movb (%rsi, %rax, 1), %r9b + + cmpb %r8b, %r9b # compare each byte + jne .strcmp_fail + + testb %r8b, %r8b # if any is null, + jz .strcmp_success # both are null here + + incq %rax + + jmp strcmp + +.strcmp_fail: + xorq %rax, %rax + ret + +.strcmp_success: + movq $1, %rax + ret |