blob: e0545318e3d813feb532d8bb7b64fc3a5802531e (
plain) (
tree)
|
|
# Copyright 2022 Gabriel Jensen.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
.globl zap_streq
zap_streq:
# Address of the current left character:
#define laddr %rdi
# Address of the current right character:
#define raddr %rsi
# Current left character:
#define lchr %al
# Current right character:
#define rchr %dl
# Iterate over the strings:
.loop:
# Copy the characters into registers:
movb (laddr),lchr # lchr = *laddr
movb (raddr),rchr # rchr = *raddr
# Check if the characters are equal:
cmpb lchr,rchr # if (lchr != rchr)
jne .neq # goto neq // If not, the strings also aren't equal.
# Check if we have reached the null-terminator:
testb lchr,lchr # if (lchr == 0x0)
jz .eq # goto eq // If so, all previous characters have compared equal, and the strings are equal.
# Continue to the next characters:
incq laddr # ++laddr
incq raddr # ++raddr
jmp .loop # goto loop
# The strings have compared equal:
.eq:
movb $0xFF,%al
ret # return FF
# The strings have compared unequal:
.neq:
movb $0x0,%al
ret # return 0
|