strlen by hand in Assembly
Walk bytes until the zero terminator.
; Walk bytes until the zero terminator: strlen by hand.
global _start
section .data
name: db "workbench", 0
section .text
_start:
lea rsi, [name]
xor rcx, rcx
.scan:
cmp byte [rsi + rcx], 0
je .done
inc rcx
jmp .scan
.done:
mov rdi, rcx ; length 9
mov rax, 60 ; exit code 9
syscall
How it works
db "workbench", 0stores the string and its terminator.cmp byte [rsi + rcx], 0reads one byte at a time.- The count, 9, is the exit code.
Keywords and builtins used here
bytecmpdbglobalincjejmpleamovraxrcxrdirsisectionsyscallxor
The run, in numbers
- Lines
- 19
- Characters to type
- 308
- Tokens
- 50
- Three-star pace
- 55 tpm
At the three-star pace of 55 tokens a minute, this run takes about 55 seconds.
Step 3 of 4 in Memory & strings, step 24 of 31 in Language basics.