-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kshitij_Agarwal_hw4
102 lines (89 loc) · 1.53 KB
/
Kshitij_Agarwal_hw4
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
#Kshitij Agarwal
#G00980156
#CS 465
.data
arrayOne: .space 1000
arrayTwo: .space 1000
.text
main:
li $t0, 1 #keeps track of lenght of new number
li $t1, 0 #keeps track of position
li $t2, 0 #temp var 1
li $t3, 0 #temp var 2
li $t4, 1 #keeps track of which array to change
li $t5, 0 #keeps track of carry over
li $t6, 2 #index of number
sb $t0, arrayOne($t1)
sb $t0, arrayTwo($t1)
addNum:
li $t2, 0
li $t3, 0
lb $t2, arrayOne($t1)
lb $t3, arrayTwo($t1)
add $t2, $t2, $t3
add $t2, $t2, $t5
li $t5, 0
bgt $t2, 9, carryOver
nop
beq $t4, 1, addArrayOne
nop
j addArrayTwo
nop
carryOver:
li $t5, 1
sub $t2, $t2, 0xa
beq $t4, 1, addArrayOne
nop
j addArrayTwo
nop
addArrayOne:
sb $t2, arrayOne($t1)
add $t1, $t1, 1
beq $t1, $t0, nextNumOne
nop
j addNum
nop
addArrayTwo:
sb $t2, arrayTwo($t1)
add $t1, $t1, 1
beq $t1, $t0, nextNumTwo
nop
j addNum
nop
nextNumOne:
add $t4, $t4, 1
li $t1, 0
add $t6, $t6, 1
beq $t5, 1, longerOne
nop
j addNum
nop
longerOne:
sb $t5, arrayOne($t0)
li $t5, 0
add $t0, $t0, 1
j check
nop
nextNumTwo:
sub $t4, $t4, 1
li $t1, 0
add $t6, $t6, 1
beq $t5, 1, longerTwo
nop
j addNum
nop
longerTwo:
sb $t5, arrayTwo($t0)
li $t5, 0
add $t0, $t0, 1
j check
nop
check:
blt $t0, 1000, addNum
nop
exit:
li $t2, 0 #temp var 1
li $t3, 0 #temp var 2
b .
nop
.end