summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem/fndchr.S
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/mem/fndchr.S')
-rw-r--r--zap/source/amd64/mem/fndchr.S37
1 files changed, 21 insertions, 16 deletions
diff --git a/zap/source/amd64/mem/fndchr.S b/zap/source/amd64/mem/fndchr.S
index 1078a10..67e0ea1 100644
--- a/zap/source/amd64/mem/fndchr.S
+++ b/zap/source/amd64/mem/fndchr.S
@@ -5,39 +5,44 @@
.globl zap_fndchr
zap_fndchr:
- # rdi: Address of the first character.
- # rsi: Character to be found.
- # rax: Address of the current character.
- # rdx: Current character.
+# Address of the first character:
+#define start %rdi
+# Character to be found:
+#define cmp %sil
+# Address of the current character:
+#define addr %rax
+# Current character:
+#define chr %dl
- movq %rdi,%rax
+ movq start,addr # addr = start
# Iterate over the string:
.loop:
# Copy the character into a register:
- movb (%rax),%dl
+ movb (addr),chr # chr = *addr
# Check if we have found the character:
- cmpb %dl,%sil
- je .fnd
+ cmpb chr,cmp # if (chr == cmp)
+ je .fnd # goto fnd
# Check if we have found the null-terminator:
- testb %dl,%dl
- jz .nfnd
+ testb chr,chr # if (chr == 0x0)
+ jz .nfnd # goto nfnd
# Continue to the next character:
- incq %rax
- jmp .loop
+ incq addr # ++addr
+ jmp .loop # goto loop
# Found:
.fnd:
- subq %rdi,%rax
- ret
+ # Get the offset of the character:
+ subq start,addr # addr -= start
+ ret # return addr
# Not found:
.nfnd:
- movq $0xFFFFFFFFFFFFFFFF,%rax
- ret
+ movq $0xFFFFFFFFFFFFFFFF,addr # addr = FFFFFFFFFFFFFFFF
+ ret # return addr