diff options
Diffstat (limited to 'zap/source/amd64/mem/fndbyte.S')
-rw-r--r-- | zap/source/amd64/mem/fndbyte.S | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/zap/source/amd64/mem/fndbyte.S b/zap/source/amd64/mem/fndbyte.S index 9298b73..af2ee84 100644 --- a/zap/source/amd64/mem/fndbyte.S +++ b/zap/source/amd64/mem/fndbyte.S @@ -5,40 +5,46 @@ .globl zap_fndbyte zap_fndbyte: - # rax: Address of the current element. - # rdi: Address of the first element. - # rsi: Address of the element after the last element. - # rdx: Byte value. - # rcx: Current byte. +# Address of the current element: +#define addr %rax +# Address of the first element: +#define start %rdi +# Address of the element after the last element: +#define afterbuf %rsi +# Byte value: +#define cmp %dl +# Current byte: +#define val %cl - movq %rdi,%rax + movq start,addr # addr = start - addq %rdi,%rsi + addq start,afterbuf # afterbuf += start # Iterate over the array: .loop: # Check if we have reached the end of the array: - cmpq %rax,%rsi - je .nfnd + cmpq addr,afterbuf # if (addr == afterbuf) + je .nfnd # goto nfnd # Check if we have found the byte value: - movb (%rax),%cl - cmpb %cl,%dl - je .fnd + movb (addr),val # val = *addr + cmpb val,cmp # if (val == cmp) + je .fnd # goto fnd # Continue to the next byte: - incq %rax - jmp .loop + incq addr # ++addr + jmp .loop # goto loop # Found: .fnd: - subq %rdi,%rax - ret + # Get the offset of the byte: + subq start,addr # addr -= start + ret # return addr # Not found: .nfnd: - movq $0xFFFFFFFFFFFFFFFF,%rax - ret + movq $0xFFFFFFFFFFFFFFFF,addr # addr = FFFFFFFFFFFFFFFF + ret # return addr |