我想尝试将 C 程序转换为 MIPS 汇编编码
这是C语言程序:
int x=2;
int index;
for(index = 0;index<4;index++){
x=x+index;
}
这是我对 MIPS 汇编编码的尝试:
li $8,4 # the limit
li $9,2 #x = 2
li $10,0 #index, starts at 0
forLoop:
slt $11,$10,$8 #if index <4 then $11 = true =1
beq $11,$0,Exit #if $11 = 0 = false means reached 4, then exit
add $9,$9,$10 #adding the index with the value in x
addi $10,1 # add 1 to the index if didnt reach the limit
j forLoop # repeat the loop
Exit:
nop #end
需要问大家这是否正确,因为我没有mips模拟器,不知道如何结束程序,nop是有效的退出计划吗?