-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.s
176 lines (172 loc) · 2.69 KB
/
main.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
.bss
.global C
C:
.space 80000
.data
.global P
P:
.word 10000007
.text
.global main
main:
# start of prologue
addi sp, sp, -72
sw ra, 44(sp)
sw fp, 48(sp)
# end of prologue
# start of body
li t0, 5996
mv t1, t0
li t0, 1
la t2, C
li t3, 0
li t4, 0
li t5, 0
li t6, 40000
li a0, 4
mul a1, t3, t6
add t3, t5, a1
mv t5, t3
mul t3, t4, a0
add t4, t5, t3
mv t5, t4
add t3, t5, t2
mv t4, t3
lw t3, 0(t4)
add t3, t5, t2
mv t2, t3
sw t0, 0(t2)
li t0, 0
mv t2, t0
li t0, 1
mv t3, t0
sw t1, 52(sp)
sw t2, 56(sp)
sw t3, 60(sp)
_L1:
lw t0, 60(sp)
lw t1, 52(sp)
sw t0, -4(sp)
sgt t0, t0, t1
xori t2, t0, 1
lw t0, -4(sp)
sw t1, 52(sp)
sw t0, 60(sp)
beq x0, t2, _L3
li t0, 0
mv t1, t0
sw t1, 64(sp)
_L4:
lw t0, 64(sp)
lw t1, 60(sp)
sw t0, -4(sp)
sgt t0, t0, t1
xori t2, t0, 1
lw t0, -4(sp)
sw t1, 60(sp)
sw t0, 64(sp)
beq x0, t2, _L6
lw t0, 64(sp)
seqz t1, t0
sw t0, 64(sp)
beq x0, t1, _L7
li t0, 1
mv t1, t0
sw t1, 68(sp)
j _L8
_L7:
la t0, C
li t1, 0
li t2, 40000
li t3, 4
lw t4, 56(sp)
mul t5, t4, t2
add t2, t1, t5
mv t1, t2
lw t2, 64(sp)
mul t5, t2, t3
add t3, t1, t5
mv t1, t3
add t3, t1, t0
mv t0, t3
lw t1, 0(t0)
la t0, C
li t3, 1
sub t5, t2, t3
li t3, 0
li t6, 40000
li a0, 4
mul a1, t4, t6
add t6, t3, a1
mv t3, t6
mul t6, t5, a0
add t5, t3, t6
mv t3, t5
add t5, t3, t0
mv t0, t5
lw t3, 0(t0)
add t0, t1, t3
la t1, P
lw t3, 0(t1)
rem t1, t0, t3
mv t0, t1
sw t4, 56(sp)
sw t2, 64(sp)
sw t0, 68(sp)
_L8:
la t0, C
li t1, 1
lw t2, 56(sp)
sub t3, t1, t2
li t1, 0
li t4, 40000
li t5, 4
mul t6, t3, t4
add t3, t1, t6
mv t1, t3
lw t3, 64(sp)
mul t4, t3, t5
add t5, t1, t4
mv t1, t5
add t4, t1, t0
mv t5, t4
lw t4, 0(t5)
add t4, t1, t0
mv t0, t4
lw t1, 68(sp)
sw t1, 0(t0)
sw t2, 56(sp)
sw t3, 64(sp)
_L5:
li t0, 1
lw t1, 64(sp)
add t2, t1, t0
mv t1, t2
sw t1, 64(sp)
j _L4
_L6:
li t0, 1
lw t1, 56(sp)
sub t2, t0, t1
mv t1, t2
sw t1, 56(sp)
_L2:
li t0, 1
lw t1, 60(sp)
add t2, t1, t0
mv t1, t2
sw t1, 60(sp)
j _L1
_L3:
li t0, 0
mv a0, t0
j main_exit
# end of body
main_exit:
# start of epilogue
addi sp, sp, 0
lw ra, 44(sp)
lw fp, 48(sp)
addi sp, sp, 72
# end of epilogue
ret