; strings.asm — string primitives: strlen, str_eq, str_copy %include "include/syscall.inc" section .text global str_len global str_eq global str_copy ; size_t str_len(const char *s) str_len: xor rax, rax .loop: cmp byte [rdi+rax], 0 je .done inc rax jmp .loop .done: ret ; int str_eq(const char *a, const char *b) — returns 1 if equal, 0 if not str_eq: push rbx .loop: movzx rax, byte [rdi] movzx rbx, byte [rsi] cmp rax, rbx jne .not_eq test rax, rax je .equal inc rdi inc rsi jmp .loop .equal: mov rax, 1 pop rbx ret .not_eq: xor rax, rax pop rbx ret ; void str_copy(char *dst, const char *src) str_copy: .loop: movzx rax, byte [rsi] mov [rdi], al test rax, rax je .done inc rdi inc rsi jmp .loop .done: ret