-
Notifications
You must be signed in to change notification settings - Fork 1
/
out.txt
115 lines (115 loc) · 3.16 KB
/
out.txt
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
tmp0
tmp0
tmp1
tmp2
m _tmp2
m _tmp1
tmp4
# standard Decaf preamble
.text
.align 2
.globl main
main:
# BeginFunc 24
subu $sp, $sp, 8 # decrement sp to make space to save ra, fp
sw $fp, 8($sp) # save fp
sw $ra, 4($sp) # save ra
addiu $fp, $sp, 8 # set up new fp
subu $sp, $sp, 24 # decrement sp to make space for locals/temps
# _tmp0 = "hello"
.data # create string constant marked with label
_string1: .asciiz "hello"
.text
la $t2, _string1 # load label
sw $t2, -16($fp) # spill _tmp0 from $t2 to $fp-16
# s = _tmp0
lw $t0, -16($fp) # fill _tmp0 to $t0 from $fp-16
_tmp0
8
# _tmp1 = 4
need to spill
_tmp0
8
_tmp1
9
li $t1, 4 # load constant value 4 into $t1
# _tmp2 = 5
need to spill
_tmp0
8
_tmp1
9
_tmp2
10
li $t2, 5 # load constant value 5 into $t2
# PushParam _tmp2
subu $sp, $sp, 4 # decrement sp to make space for param
lw $t0, -24($fp) # fill _tmp2 to $t0 from $fp-24
sw $t0, 4($sp) # copy param value to stack
# PushParam _tmp1
subu $sp, $sp, 4 # decrement sp to make space for param
lw $t0, -20($fp) # fill _tmp1 to $t0 from $fp-20
sw $t0, 4($sp) # copy param value to stack
# _tmp3 = LCall _test
jal _test # jump to function
move $t2, $v0 # copy function return value from $v0
sw $t2, -28($fp) # spill _tmp3 from $t2 to $fp-28
# PopParams 8
add $sp, $sp, 8 # pop params off stack
# c = _tmp3
lw $t2, -28($fp) # fill _tmp3 to $t2 from $fp-28
_tmp0
8
_tmp1
9
_tmp2
10
_tmp3
10
# PushParam c
subu $sp, $sp, 4 # decrement sp to make space for param
lw $t0, -8($fp) # fill c to $t0 from $fp-8
sw $t0, 4($sp) # copy param value to stack
# LCall _PrintInt
jal _PrintInt # jump to function
# PopParams 4
add $sp, $sp, 4 # pop params off stack
# PushParam s
subu $sp, $sp, 4 # decrement sp to make space for param
lw $t0, -12($fp) # fill s to $t0 from $fp-12
sw $t0, 4($sp) # copy param value to stack
# LCall _PrintString
jal _PrintString # jump to function
# PopParams 4
add $sp, $sp, 4 # pop params off stack
# EndFunc
# (below handles reaching end of fn body with no explicit return)
move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra # return from function
_test:
# BeginFunc 4
subu $sp, $sp, 8 # decrement sp to make space to save ra, fp
sw $fp, 8($sp) # save fp
sw $ra, 4($sp) # save ra
addiu $fp, $sp, 8 # set up new fp
subu $sp, $sp, 4 # decrement sp to make space for locals/temps
# _tmp4 = a + b
lw $t0, 4($fp) # fill a to $t0 from $fp+4
lw $t1, 8($fp) # fill b to $t1 from $fp+8
add $t2, $t0, $t1
sw $t2, -8($fp) # spill _tmp4 from $t2 to $fp-8
# Return _tmp4
lw $t2, -8($fp) # fill _tmp4 to $t2 from $fp-8
move $v0, $t2 # assign return value into $v0
move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra # return from function
# EndFunc
# (below handles reaching end of fn body with no explicit return)
move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra # return from function