转换从Java到MIPS [英] Convert from Java to MIPS
问题描述
我有一个天一次考试,我真的AP preciate,如果你们可以检查我的答案。我有一小片的Java code的转换成MIPS指令,但没有备忘录可用,这是第一次我在做这样的事情。
I have an exam in a days time, and I would really appreciate it if you guys can check an answer of mine. I have to convert a small piece of java code into a MIPS instruction, but no memos are available, and this is the first time I'm doing this sort of thing.
下面是问题:
While (save[i] != k) {
save[i] = v[i];
i=i+2;
}
a)项所列的code是分配的每个第二个元素较高水平的Java程序
阵列v到数组保存。假设汇编存储的基地址
数组保存和V分别到寄存器$ S2和S3 $,你被要求转换
上述成汇编语言code Java程序。
注意:您可以自由使用不同的寄存器用于那些没有指定的变量
明确
a) The code listed above is a high level Java program that assigns each second element of array v to the array save. Assuming that the assembler stores the base addresses of the arrays save and v respectively into registers $s2 and $s3, you are asked to convert the Java program above into an assembly language code. Note: You are free to use different registers for the variables which were not specified explicitly
和这里是一个尝试:
我= $ T1
K = $ T2
loop:
sll $t3, $t1, 2 //get the offset (i*4)
add $t4, $t3, $s2 //t4 is the address for save[i]
beq $t4, $t2, exit //check the while condition
add $t5, $t3, $s3 //t5 is the address for v[i]
sw $t4, $t5 //save[i] = v[i]
addi $t1, 2 //inc i
j loop
exit:
任何帮助将大大AP preciated。
Any help would be greatly appreciated.
编辑:改变'BNE'到'BEQ
changed 'bne' to 'beq'
推荐答案
您错过了几个负载,和你的店是不正确的:
You're missing a couple of loads, and your store is incorrect:
sll $t3, $t1, 2 //get the offset (i*4)
add $t4, $t3, $s2 //t4 is the address for save[i]
lw $t5,($t4) //t5 = save[i]
beq $t5, $t2, exit //check the while condition
add $t5, $t3, $s3 //t5 is the address for v[i]
lw $t5,($t5) //t5 = v[i]
sw $t5, ($t4) //save[i] = v[i]
addi $t1, 2 //inc i
这篇关于转换从Java到MIPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!