-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.s
48 lines (43 loc) · 1.32 KB
/
input.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
SYS_READ equ 0 ; read text from stdin
SYS_WRITE equ 1 ; write text to stdout
SYS_EXIT equ 60 ; terminate the program
STDIN equ 0 ; standard input
STDOUT equ 1 ; standard output
; --------------------------------
section .bss
uinput_len equ 24 ; 24 bytes for user input
uinput resb uinput_len ; buffer for user input
; --------------------------------
section .data
prompt db "Please input some text: "
prompt_len equ $ - prompt
text db 10, "You wrote: "
text_len equ $ - text
; --------------------------------
section .text
global _start
_start:
mov rdx, prompt_len
mov rsi, prompt
mov rdi, STDOUT
mov rax, SYS_WRITE
syscall
mov rdx, uinput_len
mov rsi, uinput
mov rdi, STDIN
mov rax, SYS_READ
syscall ; -> RAX
push rax ; (1)
mov rdx, text_len
mov rsi, text
mov rdi, STDOUT
mov rax, SYS_WRITE
syscall
pop rdx ; (1)
mov rsi, uinput
mov rdi, STDOUT
mov rax, SYS_WRITE
syscall
xor edi, edi ; successful exit
mov rax, SYS_EXIT
syscall