summaryrefslogtreecommitdiff
path: root/ecomp-c/tests/example_reverse_array.easm
blob: fe5ab0ac2b66fe4aed5dd027c07f631ef2912ac8 (plain)
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
199
200
201
202
203
204
205
206
207
format binary
use32
org $1000000
jmp __global_0
; CONST N -> integer, 10
; DECL i -> integer, 0
; DECL tmp -> integer, 0
; DECL a -> array 10 of integer, array 10 of integer = { ... }
__global_0:
; LET i <- 0 
mov eax, 0
push eax
pop eax
mov [i], eax
; WHILE i 10 < 
__global_1:
mov eax, [i]
push eax
mov eax, 10
push eax
pop ebx
pop eax
cmp eax, ebx
jb __global_5
mov eax, 0
jmp __global_6
__global_5: mov eax, 1
__global_6:
push eax
pop eax
mov ebx, 0
cmp eax, ebx
je __global_3
jmp __global_4
__global_3: jmp __global_2
__global_4:
; LET a[i ] <- i 
mov eax, [i]
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, a
pop ebx
add eax, ebx
push eax
mov eax, [i]
push eax
pop eax
pop ebx
mov [ebx], eax
; LET i <- i 1 + 
mov eax, [i]
push eax
mov eax, 1
push eax
pop ebx
pop eax
add eax, ebx
push eax
pop eax
mov [i], eax
jmp __global_1
__global_2:
; LET i <- 0 
mov eax, 0
push eax
pop eax
mov [i], eax
; WHILE i 10 2 div < 
__global_7:
mov eax, [i]
push eax
mov eax, 10
push eax
mov eax, 2
push eax
pop ebx
pop eax
div ebx
push eax
pop ebx
pop eax
cmp eax, ebx
jb __global_11
mov eax, 0
jmp __global_12
__global_11: mov eax, 1
__global_12:
push eax
pop eax
mov ebx, 0
cmp eax, ebx
je __global_9
jmp __global_10
__global_9: jmp __global_8
__global_10:
; LET tmp <- i [ 
mov eax, [i]
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, a
pop ebx
add eax, ebx
push eax
pop ebx
mov eax, [ebx]
push eax
pop eax
mov [tmp], eax
; LET a[i ] <- 10 1 - i - [ 
mov eax, [i]
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, a
pop ebx
add eax, ebx
push eax
mov eax, 10
push eax
mov eax, 1
push eax
pop ebx
pop eax
sub eax, ebx
push eax
mov eax, [i]
push eax
pop ebx
pop eax
sub eax, ebx
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, a
pop ebx
add eax, ebx
push eax
pop ebx
mov eax, [ebx]
push eax
pop eax
pop ebx
mov [ebx], eax
; LET a[10 1 - i - ] <- tmp 
mov eax, 10
push eax
mov eax, 1
push eax
pop ebx
pop eax
sub eax, ebx
push eax
mov eax, [i]
push eax
pop ebx
pop eax
sub eax, ebx
push eax
pop eax
mov ebx, 4
mul ebx
push eax
mov eax, a
pop ebx
add eax, ebx
push eax
mov eax, [tmp]
push eax
pop eax
pop ebx
mov [ebx], eax
; LET i <- i 1 + 
mov eax, [i]
push eax
mov eax, 1
push eax
pop ebx
pop eax
add eax, ebx
push eax
pop eax
mov [i], eax
jmp __global_7
__global_8:
hlt
a: dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
dd $00000000
tmp: dd $00000000
i: dd $00000000