sys_write in Assembly
fd, buffer, length in rdi, rsi, rdx — then syscall.
; sys_write wants fd, buffer, length -- in rdi, rsi, rdx.
global _start
section .data
msg: db "hello, machine", 10
len: equ $ - msg ; the assembler counts for us
section .text
_start:
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, msg
mov rdx, len
syscall
mov rax, 60
xor rdi, rdi
syscall
How it works
- The
.datasection holds the message bytes and a newline. equ $ - msghas the assembler compute the length.- Syscall 1 writes; the registers are the argument order.
Keywords and builtins used here
dbequglobalmovraxrdirdxrsisectionsyscallxor
The run, in numbers
- Lines
- 18
- Characters to type
- 340
- Tokens
- 47
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 47 seconds.
Step 2 of 3 in First programs, step 2 of 31 in Language basics.