我有一个任务,我的目标是将以下 Java 代码(在 asm 文件顶部的注释块中)翻译成 mips 汇编代码。当我尝试在 QTSpim 中编译时,我收到错误消息“尝试在 0x0040007c 处执行非指令”。此外,我不断收到一个错误,说我的主标签在第 36 行第二次使用,但我不明白这是怎么可能的。任何帮助将不胜感激,谢谢。
这是我的代码:
########################################################################
# program description:
#Translate this into assembly:
#
#int w1 = 40; // use a register for this variable
#int w2 = 20; // use a register for this variable
#int total; // use a register for this variable
#int result[4]; // note: int = 1 word = 4 bytes
#
#total = w1;
#for (int i = 0; i < 4; i++) {
# total = total + w2;
# if (total > 100) {
# total = total - 100;
# }
# result[i] = total;
# System.out.println(total); // C++: cout << total << '\n';
#}
#return;
#
#
# Arguments: w1, w2, total.
#
#
#
#
########################################################################
.data
result: .word 4
.text
main:
li $s0, 40 #w1
li $s1, 20 #w2
li $s2, 0 #total
li $s3, 0 #loop counter
li $s4, 4 #loop conditional
li $s5, 100 #if conditional
add $s2, $s2, $s0
loop:
beq $s3, $s4, end #if the counter is greater than 4, exit loop
add $s2, $s2, $s1 #total = total + w2
bgt $s2, $s5, then #if total is greater than 100 branch to then
then:
sub $s2, $s2, $s5 #total = total - 100
sw $s2, result #store total into result
li $v0, 1 #print out total
move $a0, $s2
syscall
else:
sw $s2, result
li $v0, 1 #print out total
move $a0, $s2
syscall
end: