From e42b70af4a2c9a310f351601fb5e381632a7f550 Mon Sep 17 00:00:00 2001 From: mithe24 Date: Tue, 28 Oct 2025 09:58:26 +0100 Subject: strcmp for parsing command line arguments --- src/lib/strcmp.s | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/lib/strcmp.s (limited to 'src') 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 -- cgit v1.2.3-70-g09d2