Registers and mov in Assembly
Copy between registers; 32-bit writes zero the top half.
; mov copies; registers come in 64, 32, 16, and 8-bit views.
global _start
section .text
_start:
mov rax, 40 ; full 64-bit register
mov rbx, rax ; register to register
mov ecx, 2 ; 32-bit write zeroes the top half
add rbx, rcx
mov rdi, rbx ; exit code 42
mov rax, 60
syscall
How it works
mov rbx, raxcopies register to register.- Writing
ecxclears the upper 32 bits ofrcx— for free. - The exit code carries the computed 42 out.
Keywords and builtins used here
addecxglobalmovraxrbxrcxrdisectionsyscall
The run, in numbers
- Lines
- 13
- Characters to type
- 323
- Tokens
- 35
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 35 seconds.
Step 3 of 3 in First programs, step 3 of 31 in Language basics.