I've never used MIPS assembly before and it was just introduced in class. I'm working on a homework assignment, but I'm having some difficulty calling a function. Here's what I've worked out so far:
.data
.align 2
matrix_a: .word 11, 23, 31, 46, 52, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
.text
.align 2
.globl main
main:
la $a0, matrix_a #; Address of matrix_a
addi $a1, 16 #; set the second argument to the size of matrix_a, 16
jal matrix_print #; and call the function
matrix_print:
add $t3,$zero,$a0
li $t2, 0 #; And initialize $t2 = 0
add $t4, $t2, $zero #; Set $t4 = $t2, we will use $t4 for checking our loop
add $t5,$zero,$a1 #; And $t5 is our max point
Loop:
bge $t4, $t5, Exit #; If our index has reached our constraint, jump to exit
add $t2,$zero,$t4 #; Otherwise, set $t2 to equal $t4
add $t2, $t2, $t2 #; Double $t2
add $t2, $t2, $t2 #; and double it again
add $t1, $t2, $t3 #; and store $t2, the offset, + $t3, the initial address
li $v0,1 #; Get ready to system call print an int
lw $a0, 0($t1) #; Pass in $t1 to print
syscall 开发者_运维问答 #; Print
addi $t4,$t4,1 #; increment $t4 by 1
j Loop
Exit:
li $v0,10 #; Exit
syscall
The problem is that it is looping forever, so I believe that $a1 isn't coming through properly. This code work when I was setting the size directly in the function. Can anyone point me in the right direction? Thanks!
In the line addi $a1, 16
, what value does $a1 have before you add 16 to it?
精彩评论