-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread10.s
55 lines (41 loc) · 1.24 KB
/
read10.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
# read 10 numbers into an array then print the 10 numbers
# i in register $t0
# registers $t1, $t2 & $t3 used to hold temporary results
main:
li $t0, 0 # i = 0
loop0:
bge $t0, 10, end0 # while (i < 10) {
la $a0, string0 # printf("Enter a number: ");
li $v0, 4
syscall
li $v0, 5 # scanf("%d", &numbers[i]);
syscall #
mul $t1, $t0, 4 # calculate &numbers[i]
la $t2, numbers #
add $t3, $t1, $t2 #
sw $v0, ($t3) # store entered number in array
add $t0, $t0, 1 # i++;
b loop0 # }
end0:
li $t0, 0 # i = 0
loop1:
bge $t0, 10, end1 # while (i < 10) {
mul $t1, $t0, 4 # calculate &numbers[i]
la $t2, numbers #
add $t3, $t1, $t2 #
lw $a0, ($t3) # load numbers[i] into $a0
li $v0, 1 # printf("%d", numbers[i])
syscall
li $a0, '\n' # printf("%c", '\n');
li $v0, 11
syscall
add $t0, $t0, 1 # i++
b loop1 # }
end1:
jr $31 # return
.data
numbers:
.align 2 # ensure array aligned ona 4-byte boundary
.space 40 # int numbers[10];
string0:
.asciiz "Enter a number: "