typestar

call and ret in Assembly

call pushes the return address; ret pops and jumps back.

; call pushes the return address; ret pops and jumps back.
        global _start

        section .text
double:                         ; rdi -> rax = rdi * 2
        lea rax, [rdi * 2]
        ret

_start:
        mov rdi, 21
        call double             ; rax = 42
        mov rdi, rax
        call double             ; rax = 84

        mov rdi, rax
        mov rax, 60             ; exit code 84
        syscall

How it works

  1. double: is a label like any other — call makes it a function.
  2. lea rax, [rdi * 2] computes without touching flags.
  3. Two calls chain: 21 to 42 to 84.

Keywords and builtins used here

The run, in numbers

Lines
17
Characters to type
330
Tokens
41
Three-star pace
60 tpm

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

Type this snippet

Step 2 of 3 in The stack, step 20 of 31 in Language basics.

← Previous Next →