typestar

add and sub in Assembly

In-place arithmetic: the first operand is the destination.

; add and sub work in place: the first operand is the destination.
        global _start

        section .text
_start:
        mov rdi, 100
        add rdi, 30             ; 130
        sub rdi, 25             ; 105
        inc rdi                 ; 106
        dec rdi
        dec rdi                 ; 104

        mov rax, 60             ; exit code 104
        syscall

How it works

  1. add rdi, 30 accumulates straight into the exit register.
  2. inc and dec are the one-step specials.
  3. Every step is visible: 100 to 130 to 105 to 104.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
293
Tokens
34
Three-star pace
60 tpm

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

Type this snippet

Step 1 of 3 in Arithmetic, step 4 of 31 in Language basics.

← Previous Next →