-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyprog.asm~
195 lines (190 loc) · 3.06 KB
/
myprog.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
global main
extern printf
segment .bss
i$1 resq 1
sum$2 resq 1
a2$3 resq 1
a1$4 resq 1
a$5 resq 1
section .text
main:
mov rax,1
push rax
pop qword[i$1]
mov rax,0
push rax
pop qword[sum$2]
mov rdi,fmt1
mov rax,0
push rbp
call printf
pop rbp
L2:
push qword[i$1]
mov rax,10
push rax
pop rbx
pop rax
cmp rax,rbx
jl J1
mov rax,0
jmp J2
J1:
mov rax, 1
J2:
push rax
pop rax
cmp rax, 0
je L3
push qword[i$1]
mov rax,1
push rax
call add
push rax
pop qword[i$1]
push qword[sum$2]
push qword[i$1]
call add
push rax
pop qword[sum$2]
push qword[i$1]
push qword[sum$2]
mov rdi,fmt2
pop rdx
pop rsi
mov rax,0
push rbp
call printf
pop rbp
jmp L2
L3:
mov rax,0
push rax
pop rax
ret
add:
pop r15
pop qword[a2$3]
pop qword[a1$4]
push qword[a1$4]
push qword[a2$3]
pop rbx
pop rax
add rax,rbx
push rax
pop qword[a$5]
push qword[a$5]
pop rax
push r15
ret
section .data
fmt1: db ` i sum\n`, 0
fmt2: db ` %ld %ld\n`, 0
SEQ(
SEQ(
FUNC[main:],
SEQ(
SEQ(
SEQ(
SEQ(
SEQ(
SEQ[],
SEQ(
PUSHL[1],
STORE[i$1]
)
),
SEQ(
PUSHL[0],
STORE[sum$2]
)
),
SEQ(
,
PRINTF[0 i sum\n]
)
),
SEQ(
SEQ(
SEQ(
SEQ(
SEQ(
LABEL[L2],
ISLT(
PUSHV[i$1],
PUSHL[10]
)
),
JUMPF[L3]
),
SEQ(
SEQ(
SEQ(
SEQ(
SEQ(
SEQ(
PUSHV[i$1],
PUSHL[1]
),
CALL[add]
),
STORE[i$1]
),
),
SEQ(
SEQ(
SEQ(
PUSHV[sum$2],
PUSHV[i$1]
),
CALL[add]
),
STORE[sum$2]
)
),
SEQ(
SEQ(
PUSHV[i$1],
PUSHV[sum$2]
),
PRINTF[2 %ld %ld\n]
)
)
),
JUMP[L2]
),
LABEL[L3]
)
),
SEQ(
PUSHL[0],
RET[]
)
)
),
SEQ(
SEQ(
SEQ(
FUNC[add:],
STORE[a2$3]
),
STORE[a1$4]
),
SEQ(
SEQ(
SEQ[],
SEQ(
ADD(
PUSHV[a1$4],
PUSHV[a2$3]
),
STORE[a$5]
)
),
SEQ(
PUSHV[a$5],
RET[]
)
)
)
)