...
This commit is contained in:
32
src/compilation/CLI/Runtime/nub_string.s
Normal file
32
src/compilation/CLI/Runtime/nub_string.s
Normal file
@@ -0,0 +1,32 @@
|
||||
.intel_syntax noprefix
|
||||
|
||||
.text
|
||||
.globl nub_string_length
|
||||
# func nub_string_length(string: string): u64
|
||||
nub_string_length:
|
||||
mov rsi, [rdi] # Length of string in bytes
|
||||
|
||||
add rdi, 8 # Start of bytes
|
||||
xor rax, rax # Character count
|
||||
xor rdx, rdx # Current byte position
|
||||
|
||||
test rsi, rsi
|
||||
jz _done
|
||||
|
||||
_count_loop:
|
||||
cmp rdx, rsi
|
||||
jge _done
|
||||
|
||||
mov dl, [rdi + rdx]
|
||||
and dl, 0b11000000
|
||||
cmp dl, 0b10000000
|
||||
je _skip_byte
|
||||
|
||||
inc rax
|
||||
|
||||
_skip_byte:
|
||||
inc rdx
|
||||
jmp _count_loop
|
||||
|
||||
_done:
|
||||
ret
|
||||
Reference in New Issue
Block a user