-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinput_str.s
92 lines (81 loc) · 1.06 KB
/
input_str.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
section .data
indexMsg db 'Input your name: '
lenIndexMsg equ $-indexMsg
endMsg db 'Nice to meet you, '
lenEndMsg equ $-endMsg
newline dd 0
input db ''
section .text
global _start
; main
_start:
call main
; exit from program
_exit:
push 60
pop rax
xor rdi, rdi
syscall
; print indexMsg variable
print_index:
push 1
pop rax
push 1
pop rdi
push indexMsg
pop rsi
push lenIndexMsg
pop rdx
syscall
ret
; print endMsg variable
print_end:
push 1
pop rax
push 1
pop rdi
push endMsg
pop rsi
push lenEndMsg
pop rdx
syscall
ret
; read user input
read_input:
push 0
pop rax
push 1
pop rdi
mov rsi, input
mov rdx, 30
syscall
ret
print_input:
push 1
pop rax
push 1
pop rdi
mov rsi, input
mov rdx, 30
syscall
ret
; print \n
print_newline:
push 1
pop rax
mov word [newline], 10
mov rsi, newline
push 1
pop rdi
push 2
pop rdx
syscall
ret
main:
call print_newline
call print_index
call read_input
call print_end
call print_input
call print_newline
call _exit