typestar

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

  1. db "workbench", 0 stores the string and its terminator.
  2. cmp byte [rsi + rcx], 0 reads one byte at a time.
  3. The count, 9, is the exit code.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 4 in Memory & strings, step 24 of 31 in Language basics.

← Previous Next →