-
Notifications
You must be signed in to change notification settings - Fork 5
/
hello.S
138 lines (115 loc) · 1.69 KB
/
hello.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
.data
.globl COMPILER__a_
COMPILER__a_:
.word 10
.text
.globl inc
inc:
addi sp, sp, -32
la t0, COMPILER__a_
lw t0, 0(t0)
li t4, 32
add t4, t4, sp
sw t0, (t4)
lw t0, 32(sp)
li t1, 1
add t0, t1, t0
sw t0, 28(sp)
lw t0, 28(sp)
la t1, COMPILER__a_
sw t0, 0(t1)
la t0, COMPILER__a_
lw t0, 0(t0)
li t4, 24
add t4, t4, sp
sw t0, (t4)
lw a0, 24(sp)
addi sp, sp, 32
ret
.text
.globl print_a
print_a:
addi sp, sp, -32
la t0, COMPILER__a_
lw t0, 0(t0)
li t4, 32
add t4, t4, sp
sw t0, (t4)
sw ra, 28(sp)
lw a0, 32(sp)
call putint
sw a0, 24(sp)
lw ra, 28(sp)
sw ra, 20(sp)
li t0, 10
sw t0, 16(sp)
lw a0, 16(sp)
call putch
sw a0, 12(sp)
lw ra, 20(sp)
li a0, 0
addi sp, sp, 32
ret
.text
.globl main
main:
addi sp, sp, -112
li t0, 0
sw t0, 112(sp)
j while_1
while_1:
lw t0, 112(sp)
sw t0, 108(sp)
lw t0, 108(sp)
li t1, 10
slt t0, t0, t1
sw t0, 104(sp)
lw t0, 104(sp)
bnez t0, while_then_1
j end_while_1
while_then_1:
sw ra, 100(sp)
call inc
sw a0, 96(sp)
lw ra, 100(sp)
li t0, 1
sw t0, 92(sp)
lw t0, 92(sp)
sw t0, 88(sp)
lw t0, 88(sp)
li t1, 2
add t0, t1, t0
sw t0, 84(sp)
lw t0, 84(sp)
sw t0, 92(sp)
lw t0, 92(sp)
sw t0, 80(sp)
sw ra, 76(sp)
lw a0, 80(sp)
call putint
sw a0, 72(sp)
lw ra, 76(sp)
sw ra, 68(sp)
li t0, 10
sw t0, 64(sp)
lw a0, 64(sp)
call putch
sw a0, 60(sp)
lw ra, 68(sp)
sw ra, 56(sp)
call print_a
sw a0, 52(sp)
lw ra, 56(sp)
lw t0, 112(sp)
sw t0, 48(sp)
lw t0, 48(sp)
li t1, 1
add t0, t1, t0
sw t0, 44(sp)
lw t0, 44(sp)
sw t0, 112(sp)
j while_1
end_while_1:
li a0, 0
addi sp, sp, 112
ret