-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.asm
198 lines (182 loc) · 2.82 KB
/
out.asm
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
global _start
section .text
_start:
enter 0, 0
call _code
jmp _exit
_output:
enter 0, 0
mov rax, 1 ; syscall number: 1 for write
mov rdi, 1 ; arg: file descriptor: 1 is stdout
mov rsi, r15 ; arg: prointer to buffer
mov rdx, 1 ; arg: only write one byte
syscall
leave
ret
_input:
enter 0, 0
mov rax, 0 ; syscall number: 0 for read
mov rdi, 0 ; arg: file descriptor: 0 is stdin
mov rsi, r15 ; arg: prointer to buffer
mov rdx, 1 ; arg: only read one byte
syscall
leave
ret
_exit:
mov rax, 60 ; exit syscall: 60
mov rdi, 0 ; Return value: 0
syscall
_code:
enter 8192, 0
mov r15, rbp
sub r15, 8
opening_lbl0:
cmp DWORD [r15], 0
jz closing_lbl0
call _input
call _output
opening_lbl1:
cmp DWORD [r15], 0
jz closing_lbl1
call _output
jmp opening_lbl1
closing_lbl1:
call _input
call _output
call _output
call _input
call _input
call _input
inc DWORD [r15]
call _input
dec DWORD [r15]
call _input
add r15, 4
sub r15, 4
call _input
opening_lbl2:
cmp DWORD [r15], 0
jz closing_lbl2
jmp opening_lbl2
closing_lbl2:
call _output
call _output
jmp opening_lbl0
closing_lbl0:
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
opening_lbl3:
cmp DWORD [r15], 0
jz closing_lbl3
sub r15, 4
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
opening_lbl4:
cmp DWORD [r15], 0
jz closing_lbl4
sub r15, 4
inc DWORD [r15]
inc DWORD [r15]
sub r15, 4
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
sub r15, 4
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
sub r15, 4
inc DWORD [r15]
add r15, 4
add r15, 4
add r15, 4
add r15, 4
dec DWORD [r15]
jmp opening_lbl4
closing_lbl4:
sub r15, 4
inc DWORD [r15]
sub r15, 4
inc DWORD [r15]
sub r15, 4
dec DWORD [r15]
sub r15, 4
sub r15, 4
inc DWORD [r15]
opening_lbl5:
cmp DWORD [r15], 0
jz closing_lbl5
add r15, 4
jmp opening_lbl5
closing_lbl5:
add r15, 4
dec DWORD [r15]
jmp opening_lbl3
closing_lbl3:
sub r15, 4
sub r15, 4
call _output
sub r15, 4
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
call _output
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
call _output
call _output
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
call _output
sub r15, 4
sub r15, 4
call _output
add r15, 4
dec DWORD [r15]
call _output
add r15, 4
call _output
inc DWORD [r15]
inc DWORD [r15]
inc DWORD [r15]
call _output
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
call _output
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
dec DWORD [r15]
call _output
sub r15, 4
sub r15, 4
inc DWORD [r15]
call _output
sub r15, 4
inc DWORD [r15]
inc DWORD [r15]
call _output
leave
ret