微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

关于 MIPS 指令的两个问题

如何解决关于 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 举报,一经查实,本站将立刻删除。