-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTastier.s
300 lines (300 loc) · 7.57 KB
/
Tastier.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
; Procedure set
setBody
LDR R5, =22
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; i
MOV TOP, BP ; reset top of stack
LDR BP, [TOP,#12] ; and stack base pointers
LDR PC, [TOP] ; return from set
set
LDR R0, =1 ; current lexic level
LDR R1, =0 ; number of local variables
BL enter ; build new stack frame
B setBody
MainBody
LDR R5, =2
LDR R2, =33
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; pic
LDR R5, =3
LDR R2, =3
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; xy
LDR R2, =33
ADD R2, R4, R2, LSL #2
LDR R0, [R2] ; b
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R0, [R2] ; i
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L1
DCB "pic.b := ", 0
ALIGN
L1
LDR R2, =0
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; i
MOV R0, R5
BL TastierPrintIntLf
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L2
DCB "Constant xy = ", 0
ALIGN
L2
LDR R2, =3
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; xy
MOV R0, R5
BL TastierPrintIntLf
LDR R5, =2
LDR R0, =2
LDR R5, =82
LDR R2, =4
ADD R2, R4, R2, LSL #2
STR R5, [R2, R0, LSL #2] ; value of zzz[]
LDR R6, =2
LDR R5, =3
CMP R5, R6
MOVLE R5, #1
MOVGT R5, #0
MOVS R5, R5 ; reset Z flag in CPSR
BEQ L3 ; jump on condition false
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L4
DCB "Index rows out of bounds", 0
ALIGN
L4
L3
LDR R2, =4
ADD R2, R4, R2, LSL #2
LDR R6, [R2, R6, LSL #2] ; value of zzz[]
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R6, [R2] ; i
LDR R2, =0
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; i
MOV R0, R5
BL TastierPrintIntLf
LDR R5, =0
LDR R0, =0
LDR R5, =88
LDR R2, =4
ADD R2, R4, R2, LSL #2
STR R5, [R2, R0, LSL #2] ; value of zzz[]
LDR R6, =0
LDR R5, =3
CMP R5, R6
MOVLE R5, #1
MOVGT R5, #0
MOVS R5, R5 ; reset Z flag in CPSR
BEQ L5 ; jump on condition false
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L6
DCB "Index rows out of bounds", 0
ALIGN
L6
L5
LDR R2, =4
ADD R2, R4, R2, LSL #2
LDR R6, [R2, R6, LSL #2] ; value of zzz[]
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R6, [R2] ; i
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L7
DCB "[0]zzz = ", 0
ALIGN
L7
LDR R2, =0
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; i
MOV R0, R5
BL TastierPrintIntLf
LDR R5, =2
LDR R0, =2
LDR R5, =2
LDR R6, =4
MUL R5, R6, R5
ADD R0, R0, R5
LDR R7, =77
LDR R2, =15
ADD R2, R4, R2, LSL #2
STR R7, [R2, R0, LSL #2] ; value of yyy[]
LDR R6, =2
LDR R5, =4
CMP R5, R6
MOVLE R5, #1
MOVGT R5, #0
MOVS R5, R5 ; reset Z flag in CPSR
BEQ L8 ; jump on condition false
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L9
DCB "Index rows out of bounds", 0
ALIGN
L9
L8
LDR R8, =2
LDR R9, =4
MUL R8, R9, R8
ADD R6, R6, R8
LDR R2, =15
ADD R2, R4, R2, LSL #2
LDR R9, [R2, R6, LSL #2] ; value of yyy[]
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R9, [R2] ; i
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L10
DCB "yyy[2][2] = ", 0
ALIGN
L10
LDR R2, =0
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; i
MOV R0, R5
BL TastierPrintIntLf
LDR R5, =2
LDR R2, =0
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; i
LDR R2, =0
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; i
LDR R6, =1
CMP R6, R5
MOVEQ R6, #1
MOVNE R6, #0
MOVS R6, R6 ; reset Z flag in CPSR
BEQ L12 ; jump on condition false
LDR R5, =1
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
L12
LDR R6, =2
LDR R5, =2
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
L13
LDR R6, =3
LDR R5, =3
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
B L11
L14
LDR R6, =4
LDR R5, =4
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
B L11
L15
LDR R5, =10
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
L11
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L16
DCB "j = ", 0
ALIGN
L16
LDR R2, =1
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; j
MOV R0, R5
BL TastierPrintIntLf
LDR R5, =0
LDR R2, =2
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; n
L17
LDR R2, =2
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; n
LDR R6, =3
CMP R5, R6
MOVLT R5, #1
MOVGE R5, #0
MOVS R5, R5 ; reset Z flag in CPSR
BEQ L18 ; jump on condition false
B L19
L20
LDR R2, =2
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; n
LDR R6, =1
ADD R5, R5, R6
LDR R2, =2
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; n
B L17
L19
LDR R2, =1
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; j
LDR R6, =3
ADD R5, R5, R6
LDR R2, =1
ADD R2, R4, R2, LSL #2
STR R5, [R2] ; j
B L20
L18
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L21
DCB "n = ", 0
ALIGN
L21
LDR R2, =2
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; n
MOV R0, R5
BL TastierPrintIntLf
ADD R0, PC, #4 ; string address
BL TastierPrintString
B L22
DCB "j = ", 0
ALIGN
L22
LDR R2, =1
ADD R2, R4, R2, LSL #2
LDR R5, [R2] ; j
MOV R0, R5
BL TastierPrintIntLf
StopTest
B StopTest
Main
LDR R0, =1 ; current lexic level
LDR R1, =1 ; number of local variables
BL enter ; build new stack frame
B MainBody
;Name: pic, Type: struct, Kind: var, Sort: scalar, address: 0, structType: a
;Name: i, Type: integer, Kind: var, Sort: scalar, address: 0, structType: null
;Name: j, Type: integer, Kind: var, Sort: scalar, address: 1, structType: null
;Name: n, Type: integer, Kind: var, Sort: scalar, address: 2, structType: null
;Name: xy, Type: integer, Kind: const, Sort: scalar, address: 3, structType: null
;Name: zzz, Type: integer, Kind: var, Sort: array, address: 4, structType: null
;Rows: 3, Columns: 1
;Name: xyz, Type: integer, Kind: var, Sort: array, address: 8, structType: null
;Rows: 6, Columns: 1
;Name: yyy, Type: integer, Kind: var, Sort: array, address: 15, structType: null
;Rows: 4, Columns: 4
;Name: a, Type: struct, Kind: var, Sort: scalar, address: 32, structType: null
;Name: b, Type: integer, Kind: var, Sort: scalar, address: 33, structType: a
;Name: c, Type: boolean, Kind: var, Sort: scalar, address: 34, structType: a
;Name: check, Type: struct, Kind: var, Sort: scalar, address: 35, structType: null
;Name: set, Type: undef, Kind: proc, Sort: scalar, address: 0, structType: null
;Name: main, Type: undef, Kind: proc, Sort: scalar, address: 0, structType: null