In: Computer Science
How can I write a simple MIPS program to print out the following elements of an array of the size of 10: 5,10,15,20,25,30,35,40,45,50
Given below is the code for the question. Please do rate the answer
if it helped. Thank you.
.data
arr: .word 5,10,15,20,25,30,35,40,45,50
blank: .asciiz " "
.text
main:
#load address of arr into $t0
la $t0, arr
#(index = $t1) initialize index to 0
li $t1, 0
loop:
bge $t1, 10, endloop #while index < 10
#load current element into $a0 for printing
lw $a0, ($t0)
li $v0, 1 #syscall for printing int
syscall
#print a space for separation
li $v0, 4
la $a0, blank
syscall
#update variables for next iteration
add $t1, $t1, 1
add $t0, $t0, 4 #each int takes 4 bytes, so next
element is 4 bytes away from current address
b loop
endloop:
#end program
li $v0, 10
syscall
output
-----
5 10 15 20 25 30 35 40 45 50
-- program is finished running --