Assembly MIPS中的无限循环
我正在尝试用MIPS汇编语言为一个类编写一个程序,该程序将从一个单词中读取一系列整数,并打印出最高值和最低值。到目前为止,我只是想让它打印出最高的值。我已经修改了课程中提供的一些代码,并使用qt SPIM逐步完成了它。我相信我的条件语句永远不会被计算。我认为我无法加载下一个单词,而且我的比较从未导致程序增加。我已经试了很多次排除故障,但还是被卡住了。下面是完整的代码。我会指出我认为错误的地方。我可以从QT看出我的循环是无限的Assembly MIPS中的无限循环,assembly,mips,Assembly,Mips,我正在尝试用MIPS汇编语言为一个类编写一个程序,该程序将从一个单词中读取一系列整数,并打印出最高值和最低值。到目前为止,我只是想让它打印出最高的值。我已经修改了课程中提供的一些代码,并使用qt SPIM逐步完成了它。我相信我的条件语句永远不会被计算。我认为我无法加载下一个单词,而且我的比较从未导致程序增加。我已经试了很多次排除故障,但还是被卡住了。下面是完整的代码。我会指出我认为错误的地方。我可以从QT看出我的循环是无限的 .text main: la $a0
.text
main:
la $a0, TABLE # Load a value for argument
la $a1, n # Load the second argument
jal high_low # jump to high_low subroutine
move $a0, $v0 # Load the return of subroutine into argument
li $v0, 1 # print out the result from the subroutine
syscall
b exit
### high_low subroutine ###
### returns the sum of the highest and lowest integer:
subu $sp, $sp, 8 # Setup a stack frame by allocating space
sw $ra, 4($sp) # Store the return address
sw $fp, ($sp) # Store the old frame pointer
addu $fp, $sp, 8 # Reset the frame pointer to the bottom of current frame
move $t0, $a0 # Load first argument into $t0
move $t1, $a1 # Load second argument into $t1
li $t2, 0 # Initialize the value of $t2, this will be the counter
high_low_loop:
bgt $t2, $t1, counting_sum_end # If the first number is larger, the loop ends
# is this how i would get to the next integer in table? I feel this is where
# i am incorrect and thus my conditional is never evaluated.
addu $t3, $t0, 4 # move next digit to be read
bgt $t0, $t3, G1 # if t0 is great increment
G1:
addi $t2, $t2, 1 # Increment $t0
bgt $t3, $t0, G2 # if t3 is bigger move it to t1 & increment
G2:
move $t3, $t0 # move to t0, if t3 is larger
addi $t2, $t2, 1 # increment counter
addi $t2, $t2, 1 # increment counter
b high_low_loop # and repeat the loop
counting_sum_end:
move $v0, $t0 # Load highest into $v0 for return
lw $fp, ($sp) # Unpack the stack frame
lw $ra, 4($sp) # load the return address into $ra
addu $sp, $sp, 8 # restore stack pointer
jr $ra
exit: li $v0, 10 # load exit instruction
syscall # and end program
.data
#TABLE: .word 3 -1 6 5 7 -3 -15 18 2
#n: .word 9
TABLE: .word 3
n: .word 1
# end of add.asm
在你看到G1和G2的地方,我觉得我必须加入一些东西才能把它送回循环的开始。例如:b high_low_循环,但我收到一个语法错误。任何方向都很好,因为我对mips非常陌生。为什么
表
只有一个元素?我只是测试它,看看是否可以让循环通过一次。自从发布这篇文章以来,我学到了很多关于这应该如何进行的知识。也许我会很快更新这篇文章,告诉大家现在的情况,以防其他人发现它有用