大于,小于等于,大于以MIPS等于 [英] Greater than, less than equal, greater than equal in MIPS

查看:3476
本文介绍了大于,小于等于,大于以MIPS等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于两个寄存器 $ S0 $ S1 ,我怎么能转换成以下伪code成仅使用 SLT (设置小于)和 BEQ BNE (分支如果相等,分支如果不相等)指令。

 如果($ S0> $ S1){转到LABEL1}
   如果($ S0> = $ S1){转到LABEL2}
   如果($ S0< = $ S1){去LABEL3}


解决方案

  SLT $ T1,$ S1,S0 $#检查$ S0> $ S1
BEQ $ T1,1,LABEL1#如果$ S0> $ S1,去LABEL1
BEQ $ S1,S2 $,LABEL2#如果$ S0 = $ S2,去LABEL2
BEQ $ T1,$零,LABEL3#如果$ S0< $ S1,去LABEL3

我假设伪code顺序执行,而且你不能去两个不同的标签。

Given two registers $s0, $s1, how can I convert the following pseudocode into MIPS assembly language using only the slt (set on less than) and beq and bne (branch if equal, branch if not equal) instructions.

   if ($s0 > $s1) { goto label1 }
   if ($s0 >= $s1) { goto label2 }
   if ($s0 <= $s1) { go to label3 }

解决方案

slt $t1,$s1,$s0      # checks if $s0 > $s1
beq $t1,1,label1     # if $s0 > $s1, goes to label1
beq $s1,$s2,label2   # if $s0 = $s2, goes to label2 
beq $t1,$zero,label3 # if $s0 < $s1, goes to label3

I'm assuming that the pseudocode executes sequentially, and that you can't go to two different labels.

这篇关于大于,小于等于,大于以MIPS等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆