-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_input_and_output.asm
64 lines (55 loc) · 1.21 KB
/
array_input_and_output.asm
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
.data
array: .space 2000 #2000 bytes
space: .asciiz" "
Size: .asciiz"Enter the number of integers less than 500: "
inputMsg: .asciiz"\nEnter the elements of array: "
outputMsg: .asciiz"\nArray: "
.text
main:
#print string Size
li $v0,4
la $a0,Size
syscall
#Number of input arraysize
li $v0,5 #for taking input
syscall
move $s1,$v0 #s1=5 integers
mul $s1,$s1,4 #s1=20 bytes
#printing inputMsg, asking for elements of the array
li $v0,4
la $a0, inputMsg
syscall
addi $s0,$zero,0 #i=0
inputLoop:
#s0(i) will be 0,4,8,12,16.... if S0==20, exit the loop
beq $s0,$s1, output #S0==s1, go to output, finished taking input
li $v0,5 #taking input
syscall
move $t1,$v0
#store value in array
sw $t1, array($s0) #array[0]= $t1 0,4,8,12,16
addi $s0,$s0,4 #i=i+4
j inputLoop
output:
#printing outputMsg
li $v0,4
la $a0,outputMsg
syscall
addi $s0,$zero,0
printLoop:
beq $s0,$s1,Exit
lw $t4, array($s0) #t4=array[i]
#print the instant array position value
li $v0,1 #printing an integer
move $a0,$t4
syscall
#print a space after a number
li $v0,4
la $a0,space
syscall
#increment index, s0= s0+4
addi $s0,$s0,4 #i=i+4
j printLoop
Exit:
li $v0,10
syscall