typestar

lea in Assembly

Compute an address without loading it: free arithmetic.

; lea computes an address without touching memory: free arithmetic.
        global _start

        section .text
_start:
        mov rax, 5
        mov rbx, 7

        lea rcx, [rax + rbx]        ; 12, plain add
        lea rcx, [rcx + rcx * 4]    ; times 5 in one instruction
        lea rdi, [rcx + 6]          ; 66

        mov rax, 60                 ; exit code 66
        syscall

How it works

  1. lea runs the address math and keeps the number.
  2. [rcx + rcx * 4] is times five in a single instruction.
  3. Compilers lean on this constantly; now you know why.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
313
Tokens
49
Three-star pace
55 tpm

At the three-star pace of 55 tokens a minute, this run takes about 53 seconds.

Type this snippet

Step 2 of 4 in Memory & strings, step 23 of 31 in Language basics.

← Previous Next →