我之前从未使用过MIPS程序集,它刚刚在课堂上介绍过。我正在做家庭作业,但是我在调用函数时遇到了一些困难。这是我到目前为止所做的:
.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
问题在于它是永远循环的,所以我认为$ a1没有正常通过。当我在函数中直接设置大小时,此代码有效。谁能指出我正确的方向?谢谢!
答案 0 :(得分:1)
在行addi $a1, 16
中,$ a1在向其添加16之前有什么价值?