assembly-playground/x86-64/in-out/in-out.asm

26 lines
554 B
NASM
Raw Normal View History

2024-06-11 19:54:36 +07:00
format ELF64 executable 0
segment readable executable
entry $
; read from stdin
2024-06-12 13:38:38 +07:00
xor rax, rax ; is rax and rax equal to itself? yes? rax is set to 0 (for sys_read)
xor rdi, rdi ; same thing but rdi (for stdin)
mov rsi, buf ; direct addressing - move address of buf to rsi (buffer address)
mov rdx, 80 ; buffer size
syscall
2024-06-11 19:54:36 +07:00
2024-06-12 13:38:38 +07:00
; write to stdout
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rdx, 80
syscall
; exit program
xor rdi, rdi ; exit code 0
mov rax, 60 ; sys_exit
syscall
2024-06-11 19:54:36 +07:00
segment readable writable
buf rb 80