-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintArrayWhileLoop.asm
More file actions
165 lines (118 loc) · 2.99 KB
/
printArrayWhileLoop.asm
File metadata and controls
165 lines (118 loc) · 2.99 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
.data
myArray: .space 12
myComma: .asciiz ", "
message1: .asciiz "Displaying array NOT USING while looping: "
message2: .asciiz "\nDisplaying array USING while loopiing: "
.text
#main procedure
main:
#calling driver function to display array using while loop
jal printArrayLoop
#cant seem to figure out why only 1 array displays
#calling driver function
jal printArray
#closing statement
li $v0, 10
syscall
#driver function for printing array without while loop
printArray:
addi $s0, $zero, 4
addi $s1, $zero, 10
addi $s2, $zero, 12
addi $t0, $zero, 0 #at first position
sw $s0, myArray($t0)
addi $t0, $t0, 4 #at second position
sw $s1, myArray($t0)
addi $t0, $t0, 4 #at thrid position
sw $s2, myArray($t0)
#printint values of array without using while loop
subi $t0, $t0, 8 #moving index to position 1
#retrieving value at first position of array using LOAD WORD(lw) instruction
lw $t6, myArray($t0) #load value at 3rd position from myArray(4) into t6
#display message1
jal displayMessage1
#calling function to display int at first position
jal displayInt
#calling dipslayComma function to dipslay comma
jal displayComma
#changing index to second position
addi $t0, $t0, 4
#loading new array position value into t6
lw $t6, myArray($t0)
#display next int
jal displayInt
#display a comma
jal displayComma
#changing index to third position
addi $t0, $t0, 4
#loading new array position value into t6
lw $t6, myArray($t0)
#display last int
jal displayInt
#closing statement
jr $ra
#driver functin to print array using looping
printArrayLoop:
#'declaring' values
addi $s0, $zero, 4
addi $s1, $zero, 10
addi $s2, $zero, 12
addi $t0, $zero, 0 #specify starting index
sw $s0, myArray($t0)
addi $t0, $t0, 4 #at second position
sw $s1, myArray($t0)
addi $t0, $t0, 4 #at thrid position
sw $s2, myArray($t0)
#clearing t0 to 0
addi $t0, $zero, 0
#displaying message2
jal displayMessage2
while:
#test condition
beq $t0, 12, exit #if t0 = 12, then break out of while loop
lw $t6, myArray($t0) #load element to register t0
#updating offset
addi $t0, $t0, 4
#calling displayInt to print current number
li $v0, 1
addi $a0, $t6, 0
syscall
#displaying comma
li $v0, 4
la $a0, myComma
syscall
j while #iterator
exit:
#tell system this is end of loop
li $v0, 10
syscall
#closing statement
jr $ra
#function to display an integer
displayInt:
li $v0, 1
addi $a0, $t6, 0
syscall
#closing statement
jr $ra
#function to display a comma
displayComma:
li $v0, 4
la $a0, myComma
syscall
#closing statement
jr $ra
#function to display message1
displayMessage1:
li $v0, 4
la $a0, message1
syscall
#closing statement
jr $ra
#function to display message2
displayMessage2:
li $v0, 4
la $a0, message2
syscall
#closing statement
jr $ra