-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.s
169 lines (169 loc) · 3.21 KB
/
output.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
#author Anna Wang
#version 3/20/18
.data
line: .asciiz "\n"
x: .word 0
y: .word 0
ignore: .word 0
.text
.globl main
main:
li $v0 2
sw $v0 x #loading value of expression to v0
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
li $v0 1
lw $t0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
addu $v0, $t0, $v0 #adds
sw $v0 y #loading value of expression to v0
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
lw $v0 y
lw $t0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
addu $v0, $t0, $v0 #adds
sw $v0 x #loading value of expression to v0
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
lw $v0 y
lw $t0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
mult $v0, $t0
mflo $v0 #multiplies
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 x
move $t1 $v0
lw $v0 y
bgt $t1 $v0 endif1
j mergeendif1
endif1:
lw $v0 x
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 y
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
j mergeendif1
mergeendif1:
li $v0 0
sw $v0 x #loading value of expression to v0
lw $v0 x
move $t1 $v0
li $v0 10
blt $t1 $v0 loop
j exit
loop:
lw $v0 x
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
li $v0 1
lw $t0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
addu $v0, $t0, $v0 #adds
sw $v0 x #loading value of expression to v0
lw $v0 x
move $t1 $v0
li $v0 10
blt $t1 $v0 loop
exit:
lw $v0 y
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
subu $sp, $sp, 4
sw $ra, ($sp) #pushes value onto stack of addresses
li $v0 4
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
lw $v0 y
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
jal procAdd
lw $a0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
lw $a0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
lw $a0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
lw $ra, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
sw $v0 ignore #loading value of expression to v0
lw $v0 x
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
li $v0, 10
syscall
procAdd:
li $v0 0
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
subu $sp, $sp, 4
sw $ra, ($sp) #pushes value onto stack of addresses
lw $v0 16($sp)
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 12($sp)
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 8($sp)
move $a0 $v0
li $v0 1
syscall
la $a0, line
li $v0 4
syscall
lw $v0 x
subu $sp, $sp, 4
sw $v0, ($sp) #pushes value onto stack of addresses
lw $v0 20($sp)
lw $t0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
addu $v0, $t0, $v0 #adds
sw $v0 x #loading value of expression to v0
lw $ra, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses
jr $ra
lw $v0, ($sp)
addu $sp, $sp, 4 #pop value off stack of addresses