39 lines
752 B
NASM
39 lines
752 B
NASM
|
bits 64
|
||
|
|
||
|
SECTION .data
|
||
|
; empty
|
||
|
echobuf db 1024
|
||
|
|
||
|
SECTION .text
|
||
|
|
||
|
global _start
|
||
|
_start:
|
||
|
;int3
|
||
|
|
||
|
read:
|
||
|
; sys_read(stdin, buf, buflen)
|
||
|
mov rax,0
|
||
|
mov rdi,0 ; arg1: fd (0 = stdin)
|
||
|
lea rsi,[echobuf] ; arg2: buffer
|
||
|
mov rdx,1024 ; arg3: buflen
|
||
|
syscall
|
||
|
|
||
|
test rax, rax
|
||
|
jz exit
|
||
|
|
||
|
; sys_write(stdout, buf, buflen)
|
||
|
mov rdx,rax ; arg3: buflen
|
||
|
mov rax,1 ; system call number (1 = sys_write)
|
||
|
mov rdi,1 ; arg1: fd (1 = stdout)
|
||
|
lea rsi,[echobuf] ; arg2: buffer
|
||
|
syscall
|
||
|
jmp read
|
||
|
|
||
|
exit:
|
||
|
; sys_exit(42)
|
||
|
mov rax,60 ; system call number (sys_exit)
|
||
|
mov rdi,0 ; system call return value
|
||
|
syscall
|
||
|
|
||
|
times 64 nop
|