-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPA5obj.java.s
More file actions
434 lines (359 loc) · 9.13 KB
/
Copy pathPA5obj.java.s
File metadata and controls
434 lines (359 loc) · 9.13 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
.file "main.java"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.text
.global main
.type main, @function
main:
push r29
push r28
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
call _Z18MeggyJrSimpleSetupv
/* Need to call this so that the meggy library gets set up */
# NewExp
ldi r24, lo8(2)
ldi r25, hi8(2)
# allocating object of size 2 on heap
call malloc
# push object address
# push two byte expression onto stack
push r25
push r24
# Load constant int 3
ldi r24,lo8(3)
ldi r25,hi8(3)
# push two byte expression onto stack
push r25
push r24
# Casting int to byte by popping
# 2 bytes off stack and only pushing low order bits
# back on. Low order bits are on top of stack.
pop r24
pop r25
push r24
# Load constant int 7
ldi r24,lo8(7)
ldi r25,hi8(7)
# push two byte expression onto stack
push r25
push r24
# Casting int to byte by popping
# 2 bytes off stack and only pushing low order bits
# back on. Low order bits are on top of stack.
pop r24
pop r25
push r24
# Color expression Meggy.Color.BLUE
ldi r22,5
# push one byte expression onto stack
push r22
#### function call
# put parameter values into appropriate registers
# load a one byte expression off stack
pop r18
# load a one byte expression off stack
pop r20
# load a one byte expression off stack
pop r22
# receiver will be passed as first param
# load a two byte expression off stack
pop r24
pop r25
call C_setP
/* epilogue start */
endLabel:
jmp endLabel
ret
.size main, .-main
.text
.global C_setP
.type C_setP, @function
C_setP:
push r29
push r28
# make space for locals and params
ldi r30, 0
push r30
push r30
push r30
push r30
push r30
push r30
push r30
# Copy stack pointer to frame pointer
in r28,__SP_L__
in r29,__SP_H__
# save off parameters
std Y + 2, r25
std Y + 1, r24
std Y + 3, r22
std Y + 4, r20
std Y + 5, r18
/* done with function C_setP prologue */
# NewExp
ldi r24, lo8(1)
ldi r25, hi8(1)
# allocating object of size 1 on heap
call malloc
# push object address
# push two byte expression onto stack
push r25
push r24
### AssignStatement
# load rhs exp
# load a two byte expression off stack
pop r24
pop r25
# store rhs into var ox
std Y + 7, r25
std Y + 6, r24
# IdExp
# load value for variable ox
# variable is a local or param variable
# load a two byte variable from base+offset
ldd r25, Y + 7
ldd r24, Y + 6
# push two byte expression onto stack
push r25
push r24
# IdExp
# load value for variable x
# variable is a local or param variable
# load a one byte variable from base+offset
ldd r24, Y + 3
# push one byte expression onto stack
push r24
#### function call
# put parameter values into appropriate registers
# load a one byte expression off stack
pop r22
# receiver will be passed as first param
# load a two byte expression off stack
pop r24
pop r25
call Ind_put
# NewExp
ldi r24, lo8(1)
ldi r25, hi8(1)
# allocating object of size 1 on heap
call malloc
# push object address
# push two byte expression onto stack
push r25
push r24
### AssignStatement
# load rhs exp
# load a two byte expression off stack
pop r24
pop r25
# loading the implicit "this"
# load a two byte variable from base+offset
ldd r31, Y + 2
ldd r30, Y + 1
# store rhs into var oy
std Z + 1, r25
std Z + 0, r24
# IdExp
# load value for variable oy
# loading the implicit "this"
# load a two byte variable from base+offset
ldd r31, Y + 2
ldd r30, Y + 1
# variable is a member variable
# load a two byte variable from base+offset
ldd r25, Z + 1
ldd r24, Z + 0
# push two byte expression onto stack
push r25
push r24
# IdExp
# load value for variable y
# variable is a local or param variable
# load a one byte variable from base+offset
ldd r24, Y + 4
# push one byte expression onto stack
push r24
#### function call
# put parameter values into appropriate registers
# load a one byte expression off stack
pop r22
# receiver will be passed as first param
# load a two byte expression off stack
pop r24
pop r25
call Ind_put
# IdExp
# load value for variable ox
# variable is a local or param variable
# load a two byte variable from base+offset
ldd r25, Y + 7
ldd r24, Y + 6
# push two byte expression onto stack
push r25
push r24
#### function call
# put parameter values into appropriate registers
# receiver will be passed as first param
# load a two byte expression off stack
pop r24
pop r25
call Ind_get
# handle return value
# push one byte expression onto stack
push r24
# IdExp
# load value for variable oy
# loading the implicit "this"
# load a two byte variable from base+offset
ldd r31, Y + 2
ldd r30, Y + 1
# variable is a member variable
# load a two byte variable from base+offset
ldd r25, Z + 1
ldd r24, Z + 0
# push two byte expression onto stack
push r25
push r24
#### function call
# put parameter values into appropriate registers
# receiver will be passed as first param
# load a two byte expression off stack
pop r24
pop r25
call Ind_get
# handle return value
# push one byte expression onto stack
push r24
# IdExp
# load value for variable c
# variable is a local or param variable
# load a one byte variable from base+offset
ldd r24, Y + 5
# push one byte expression onto stack
push r24
### Meggy.setPixel(x,y,color) call
# load a one byte expression off stack
pop r20
# load a one byte expression off stack
pop r22
# load a one byte expression off stack
pop r24
call _Z6DrawPxhhh
call _Z12DisplaySlatev
/* epilogue start for C_setP */
# no return value
# pop space off stack for parameters and locals
pop r30
pop r30
pop r30
pop r30
pop r30
pop r30
pop r30
# restoring the frame pointer
pop r28
pop r29
ret
.size C_setP, .-C_setP
.text
.global Ind_put
.type Ind_put, @function
Ind_put:
push r29
push r28
# make space for locals and params
ldi r30, 0
push r30
push r30
push r30
# Copy stack pointer to frame pointer
in r28,__SP_L__
in r29,__SP_H__
# save off parameters
std Y + 2, r25
std Y + 1, r24
std Y + 3, r22
/* done with function Ind_put prologue */
# IdExp
# load value for variable i
# variable is a local or param variable
# load a one byte variable from base+offset
ldd r24, Y + 3
# push one byte expression onto stack
push r24
### AssignStatement
# load rhs exp
# load a one byte expression off stack
pop r24
# loading the implicit "this"
# load a two byte variable from base+offset
ldd r31, Y + 2
ldd r30, Y + 1
# store rhs into var _i
std Z + 0, r24
/* epilogue start for Ind_put */
# no return value
# pop space off stack for parameters and locals
pop r30
pop r30
pop r30
# restoring the frame pointer
pop r28
pop r29
ret
.size Ind_put, .-Ind_put
.text
.global Ind_get
.type Ind_get, @function
Ind_get:
push r29
push r28
# make space for locals and params
ldi r30, 0
push r30
push r30
# Copy stack pointer to frame pointer
in r28,__SP_L__
in r29,__SP_H__
# save off parameters
std Y + 2, r25
std Y + 1, r24
/* done with function Ind_get prologue */
# IdExp
# load value for variable _i
# loading the implicit "this"
# load a two byte variable from base+offset
ldd r31, Y + 2
ldd r30, Y + 1
# variable is a member variable
# load a one byte variable from base+offset
ldd r24, Z + 0
# push one byte expression onto stack
push r24
/* epilogue start for Ind_get */
# handle return value
# load a one byte expression off stack
pop r24
# promoting a byte to an int
tst r24
brlt MJ_L0
ldi r25, 0
jmp MJ_L1
MJ_L0:
ldi r25, hi8(-1)
MJ_L1:
# pop space off stack for parameters and locals
pop r30
pop r30
# restoring the frame pointer
pop r28
pop r29
ret
.size Ind_get, .-Ind_get