Java到mips组装练习
我有一个任务,目标是将以下Java代码(在asm文件顶部的注释块中)转换为mips汇编代码。当我尝试在QTSpim中编译时,我得到一个错误消息“尝试在0x0040007c处执行非指令”。另外,我不断收到一个错误,说我的主标签在第36行第二次被使用,但我不知道这是怎么可能的。任何帮助都将不胜感激,谢谢 这是我的密码:Java到mips组装练习,mips,qtspim,Mips,Qtspim,我有一个任务,目标是将以下Java代码(在asm文件顶部的注释块中)转换为mips汇编代码。当我尝试在QTSpim中编译时,我得到一个错误消息“尝试在0x0040007c处执行非指令”。另外,我不断收到一个错误,说我的主标签在第36行第二次被使用,但我不知道这是怎么可能的。任何帮助都将不胜感激,谢谢 这是我的密码: ######################################################################## # program descript
########################################################################
# 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:
########################################################################
#程序说明:
#将此转换为汇编:
#
#int w1=40;//使用此变量的寄存器
#int w2=20;//使用此变量的寄存器
#整数总计;//使用此变量的寄存器
#int结果[4];//注:int=1字=4字节
#
#总数=w1;
#对于(int i=0;i<4;i++){
#总计=总计+w2;
#如果(总数>100){
#总数=总数-100;
# }
#结果[i]=总数;
#System.out.println(total);//C++:cout一旦程序完成,您需要显式退出程序,否则CPU将继续执行程序后内存中发生的任何内容。当您使用SPIM(或从SPIM派生的其他模拟器之一)时,您可以使用syscall 10来实现以下目的:
# syscall 10 == exit
li $v0,10
syscall