aoc_omni/fasm/lib/string.inc

72 lines
1.1 KiB
PHP

;;; rdi should contain the source to copy from
;;; rsi should contain the destination pointer
;;; rdx should contain the number of bytes to copy
copy_mem_to_string:
cmp rdx, 0
jz .finish
mov r8, [rdi]
mov [rsi], r8
inc rsi
inc rdi
dec rdx
jmp copy_mem_to_string
.finish:
mov byte [rsi], 0
ret
;;; rdi should contain the source to copy from
;;; rsi should contain the destination pointer
copy_line_to_string:
mov rax, 0
.start:
cmp byte [rdi], 10
jz .finish
mov r8, [rdi]
mov [rsi], r8
inc rsi
inc rdi
inc rax
jmp copy_line_to_string
.finish:
mov byte [rsi], 0
ret
;;; rdi should contain the source to copy from
;;; rsi should contain the destination pointer
;;; dl should contain the delimiter
copy_until_token_to_string:
mov rax, 0
.start:
cmp byte [rdi], dl
jz .finish
mov r8, [rdi]
mov [rsi], r8
inc rsi
inc rdi
inc rax
jmp copy_until_token_to_string
.finish:
mov byte [rsi], 0
ret
;;; rdi should contain the string to measure
string_length:
mov rax, 0
.start:
cmp byte [rdi], 0
jz .finish
inc rdi
inc rax
jmp string_length
.finish:
ret