关于 MIPS 指令的两个问题

问题描述

一个问题:我知道根据定义,指令 Beq 有前两个寄存器,然后是跳转到的标签。但是,当我运行 Mars 编译器时,我得到例如:“beq $s6,1,Lable”运行良好。我想解释一下这个命令是否仍然有效,如果不是,那么为什么要编译它。

第二个问题 - 对于这个问题,我有以下代码

psudo code: 

   Main: 
   { 
       Func(3,12,0x12)
   }


   Func1(a,b,c)
   {
       sum=a+b+c
      Func2(sum,a,c)
       Return sum
   }
   Func2(sum,c) 
   {
       sum=sum*(a+b+c)
       Return (sum+1)
   }


Main: 
addi $a0,$0,3 #first function input a0=3
addi $a1,12 #second function input a1=12
addi $a2,0x12 #third function input a2=0x12
jal Func1 #jump to function1 with those input virables. 
add $s2 $0,$v0 #store the result of func1 at $s2.
j break #go to break. 

Func1:
addi $sp,$sp,-16 #allocate memory for 4 registers
sw $a2,-12($sp) #restore a2 = c
sw $a1,-8($sp) #restore a1 = b
sw $a0,-4($sp) #restore a0 = a
sw $ra,0($sp) #restore return address.

add $t0,$a0,$a1 #t0=a+b
add $t0,$t0,$a2 #t0+=c

add $a0,$t0 #store the result of a+b+c at $a0.
lw $t1,-4($sp) #restore t1=a
add $a1,$t1 #a1=t1 
lw $t2,-8($sp) #restore t1=b
add $a2,$t2 #a1=t2
lw $t3,-12($sp) #restore t1=c
add $a3,$t3 #a1=t3
jal Func2 #jump to func2 with the input numbers a0,a1,a2,a3.
lw $ra,0($sp) #change the return adress to the main function calling. 
addi $sp,16 #deallocate memory.
jr $ra #return

Func2:
add $t0,$a1,$a2 #t0=a+b
add $t0,$a3 #t0+=c
mult $a0,$t0 #sum*(a+b+c)
mflo $a0 #storing result in $a0
addi $v0,1 #storing result+1 at the return function variable $v0
jr $ra #return 
break: 

在这代码有效吗?因为它也在 Mars 中得到了遵守,但是,我注意到存储单词和加载都使用 - 而不是 +,考虑到 MIPS 指令是否有效? 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...