# -------------------------------------------- # 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