Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

.

text

main:
la $s1, N # N in $s1
lw $s1, 0($s1)
#li $s1, 7 ## Uncomment this line for example non-general
solution
la $s2, A # base address of A
mul $s3, $s1, 4 # calculate the size of array A (in bytes)
add $s3, $s2, $s3 # calculate the address of last (7th) element of array
A (base address + byte size of array)

loop: ble $s3, $s2, done # ble: branch if less than or equal - check if the
current element of A is located at the base address (in other words if it is our
first array element, so last to print)
addi $s3, $s3, -4 # decrement pointer to A[i] (to the preceeding element
of array A)
lw $t0, 0($s3) # load A[i] - load the current word (element) of the
array
move $a0, $t0 # prepare to print the current element
li $v0, 1 # print the current element syscall - syscall
syscall
j loop # back to checking if the current element of A is
located at the base address

done:
li $v0, 10 # exit syscall
syscall

You might also like