Repository navigation
Expand file tree
/
Copy pathcode2.txt
More file actions
166 lines (158 loc) · 4.9 KB
/
Copy pathcode2.txt
File metadata and controls
166 lines (158 loc) · 4.9 KB
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
mof* 0000 # load 0 into accumulator
mov $t1 # set max or r0 to 0
mov $t2 $ set max or r12 to 0
mof* 1111 # load immediate value 1111 into acc
mov $t3 # set min or r1 to 1111
mov $t4 # set min to 1111
Mov $t11 # set our mask (0b11111111) lower 4 bits
Lsl 0100 # left shift acc → 0b11110000
Or $t11 # or with our mask to get full mask
mov $t11 # set our mask to 0b11111111
mov $t3
mov $t4
mof* 0001 # load imm value 1 into acc
Xor $t11 # xor with mask → 0b11111110
lsl* 0010 # left shift acc value by 2 → 0b11111000
rsl* 0010 # right shift acc → 0b00111110 (62)
mov $t12 # set j_max = 62 for inner loop
add* 0010 # 62 + 2 = 64 for our start i value
mov $t6 # set i = 64 (will become 62 at loop start)
Outer_loop:
Mof $t5 # load i into acc
beq 1110 # branch to exit if i = 0
sub* 0010 # subtract i by 2
Mov $t5 # move new i value back into $t2
mof $t5
lwr $t5 # load data_mem[$t2]; value in memory
mov $t8 # save to temp2 (upper bits)
mof $t5 # move i into acc
add* 0001 # add imm value 1 to acc
mov $t15 # store $t2+1 into register
mof $t15
lwr $t15 # load data_mem[$t2+1]; value in memory
mov $t7 # save to temp1 (lower bits)
mof $t12 # load j_max into acc
mov $t4 # set j to 62 (countdown to i)
Inner_loop:
mof $t6 # move j into acc
sub $t5 # subtract i from j
beq 1000 # go out to outer loop if equal to 0
mof $t6
lwr $t6 # load data_mem[$t3]; value in memory
mov $t10 # save to temp2j (upper bits)
mof $t6 # move j into acc
add* 0001 # add imm value 1 to acc
mov $t15 # store $t3+1 into register
mof $t15
lwr $t15 # load data_mem[$t3+1]; value in memory
mov $t9 # save to temp1j (lower bits)
mof $t6 # move j into acc
sub* 0010 # subtract j by 2
mov $t6 # move new j value back into $t4
mof $t8 # move upper temp1 into acc
Xor $t11
Mov $t8
Mof $t7
Xor $t11
Mov $t7
Add* 0001 //Add 1 to finish twos complement
Mov $t15 // Save this value to t15
Cmp $t7 // compare acc with og t7
Add $t8 //add this to the upper
Mov $t8 // move this to the upper
Mof $t15 //load in new t7
Mov $t7 //move that into t7
Add $t9 //add the lower bits
Mov $t15 // save that to t15
Cmp $t9 // compare with og lower bits
Add $t8 // add uppper bit
Add $t10 // add other upper bit
Mov $t10 // save that into upper bit
Mof $t15 // load in new lower bit
Mov $t9 // move that into t9
Mof $t10 // load into t10
Rsl 0111 // right shift by 7
Bne 1010 // if negative, jump to Negative
Mof $t9 # otherwise move other lower into t14
Mov $t14
Mof $t10 # move other upper into t15
Mov $t15
Mof $t1
Cmp $t10 #compare upper to max
Bne 1100 #if its 1, update max
Mof $t10
Cmp $t1
Bne 1011 #t10 was less than max, compare min
Mof $t2 # it was equal, compare lower
Cmp $t9
Bne 1100 #lower of nonzero bits are more than, update max
J 1011
Negative:
Mof $t10 // Load in upper bits
Xor $t11 //xor
Mov $t10 // move into t10
Mof $t9 // move in t9
Xor $t11 //xor
Mov $t9 // mov bak
Add* 0001 // finish twos complement
Mov $t15 // save to t15
Cmp $t9 // compare with og
Add $t10 // add overflow
Mov $t10 // save to t10
Mof $t15
Mov $t9 # otherwise move other lower into t14
Mov $t14
Mof $t10
Mov $t15
Mof $t1
Cmp $t10 #compare upper to max
Bne 1100 #if its 1, max less than curr
Mof $t10
Cmp $t1
Bne 1011 #t10 was less than max, compare min
Mof $t2 # it was equal, compare lower
Cmp $t9
Bne 1100 #lower of nonzero bits are more than, update max
Compare_Min:
Mof $t10
Cmp $t3
Bne 1101
Mof $t3
Cmp $t10
Bne 1001
Mof $t9
Cmp $t4
Bne 1101
J 1001
New_max:
Mof $t10
Mov $t1
Mof $t9
Mov $t2
J 1001
New_min:
Mof $t10
Mov $t3
Mof $t9
Mov $t4
J 1001
exit:
mof* 0001 # load in imm val 1
lsl* 0110 # left shift 0b00000001 --> 0b 01000000
add* 0010
mov $t14 # store 66 in reg
add* 0001
Mov $t15 #store 67
mof $t1 # load upper min into acc
str $t14 # store min into respective place in memory
Mof $t2 #load lower min into acc
Str $t15 #store min
Mof $t15
Add* 0001
Mov $t14
Add* 0001
Mov $t15
mof $t3 # load min into acc
str $t14 # store min into respective place in memory
Mof $t4
Str $t15