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
add rdi, 30accumulates straight into the exit register.incanddecare the one-step specials.- Every step is visible: 100 to 130 to 105 to 104.
Keywords and builtins used here
adddecglobalincmovraxrdisectionsubsyscall
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.
Step 1 of 3 in Arithmetic, step 4 of 31 in Language basics.