forked from ColeTynan/cse141Lfinal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
16bitdivide.txt
200 lines (183 loc) · 3.98 KB
/
16bitdivide.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
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
nor $t4, $0 #to store QM
nor $s1, $0 #s1 = 0
ld $s1, $s1 #s1 = mem[0] (dividend DMSB)
nor $s2, $0 #s2 = 0
addi $s2, 2 #s2 = mem[2] (divisor V)
ld $s2, $s2
nor $c, $0 #c = -8
addi $c, -4
addi $c, -4
L1: #for j = -8; j < 0; j++
nor $t1, $0
nor $t1, $s1 #t1 = D (temp)
nor $t1, $t1
addi $c, 1 # increment c by one so we shift by the correct number of places
shf $t1, $c # t1 = D >> j + 1 = a
st $c, $0 # mem[$0] = j + 1
nor $s2, $s2 #s2 = -s2 (V = -V)
addi $s2, 1 #^
add $t1, $s2 #t1 = a - V (if this is <0 than the bneg if statement is skipped)
nor $s2, $s2 # -V -> V
addi $s2, 1
nor $c, $0 #c = 0
nor $c, $t1 #c = t1
nor $c, $c
bneg L2 #if statement 23
ld $c, $0 #c = j + 1
nor $c, $c #make j + 1 positive (ex: -7 -> 7)
addi $c, 1
nor $t1, $0
nor $t1, $s2 #t1 = V
nor $t1, $t1 #^
shf $t1, $c #V << j
nor $t1, $t1 #-V<<j
addi $t1, 1
add $s1, $t1 # s1 = D = (D - V << (j + 1)) 32
nor $t1, $0 #t1 = 0
addi $t1, 1 #t1 = 1
shf $t1, $c #t1 = 1<<(j+1)
nor $t4, $t1 #t4 = Q = Q OR (1<<(j+1))
nor $t4, $t4
L2:
ld $c, $0 #restore c = j
bneg L1
nor $t1, $0 #t1 = 0
addi $t1, 3 #t1 = 3
addi $t1, 1 #t1 = 4
st $t4, $t1 #mem[4] = QM
#nops to bypass branching problem
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
#end nops
nor $t4, $0 # t4 = 0 (hold DL)
addi $t4, 1 # t4 = 1
ld $t4, $t4 #t4 = MEM[1] DLSB
nor $c, $0 #c = -8
addi $c, -4
addi $c, -4
L3: #2nd loop, find LSB of Quotient
nor $t1, $0 #zero out temp registers
nor $t2, $0
nor $t3, $0
addi $c, 1
add $t1, $c #t1 = j
add $t2, $t4 #t2 = DL
shf $t2, $t1 #DL >> j
nor $t3, $0 #t3 = 0
addi $t3, 1 #t3 = 1
nor $t2, $t2 #t2 = (DL >> j) && 1
nor $t3, $t3
nor $t2, $t3
nor $t1, $0
addi $t1, 1 #t1 = 1
shf $s1, $t1 #s1 = DM = DM << 1 (79)
add $s1, $t2 #s1 = DM = DM + a
nor $s2, $s2 #s2 = -s2 (v = -v)
addi $s2, 1
st $c, $0 #mem[$0] = j
nor $c, $0
addi $c, 1 #c = 1
add $c, $s1 #c = DM +1
add $c, $s2 #c = DM - V + 1
nor $s2, $s2 #-v => v
addi $s2, 1
bneg L4
ld $c, $0 #c = j + 1
nor $c, $c #make j + 1 positive (ex: -7 -> 7)
addi $c, 1
nor $t1, $0
add $t1, $s2 #t1 = V
nor $t1, $t1 #-V
addi $t1, 1
add $s1, $t1 # s1 = D = (D - V << (j + 1))
nor $t1, $0 #t1 = 0
addi $t1, 1 #t1 = 1
shf $t1, $c #t1 = 1<<(j+1)
nor $t2, $0 #zero out temp
nor $t3, $0
addi $t2, 3
addi $t2, 2 #t2 = 5
ld $t3, $t2 #t3 = mem[5] (QL)
nor $t3, $t1 #t4 = Q = Q OR (1<<(j+1))
nor $t3, $t3
st $t3, $t2 #mem[5] = QL
L4:
ld $c, $0 #restore c value (iterator)
bneg L3
#nops to bypass branching problem
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
add $t4,$t4
#end nops
#3rd loop
nor $c, $0
addi $c, -4 #j = -8
addi $c, -4
L5: #for j = -8, j < 0, j ++
addi $c, 3 #j = j + 9
addi $c, 3
addi $c, 3
nor $t1, $0 #t1 = 0
addi $t1, 1
shf $s1, $t1 #DM = DM << j
nor $s2, $s2 #v = -v
addi $s2, 1
st $c, $0 #mem[255] = j
nor $c,$0 #c = 0
addi $c,1 #c= 1
add $c, $s2 #c = -V + 1
add $c, $s1 #c = DM - V + 1
nor $s2, $s2 #-v => V
addi $s2, 1
bneg L6 #if DM-V+1 < 0, skip
nor $s2, $s2 #v => -V
addi $s2, 1
add $s1, $s2 #DM = DM - V
nor $s2, $s2 # -v => V
addi $s2, 1
nor $t1, $0
addi $t1, 3
addi $t1, 3 #t1 = 6
ld $t2, $t1 #t2 = mem[6] (QFrac)
ld $t3, $0 #t3 = j
nor $t3, $t3 #155
addi $t3, 1 # t3 = -j
addi $t3, 3
addi $t3, 3
addi $t3, 2 #t3 = -j + 8
nor $t4, $0
addi $t4, 1 #t4 = 1
shf $t4, $t3 #t4 = 1<<(8-j) 162
nor $t2, $t4
nor $t2, $t2 #t2 = QFrac or (1<<(8-j))
st $t2, $t1 #mem[6] = Qfrac
L6:
ld $c, $0
addi $c, -3 #j = j - 8
addi $c, -3
addi $c, -2
bneg L5
stp