summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem/streq.S
blob: e0545318e3d813feb532d8bb7b64fc3a5802531e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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