如果在MIPS中,则存在多个条件 [英] Mutiple conditions in if in MIPS

查看:144
本文介绍了如果在MIPS中,则存在多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MIPS提供了分支指令,例如相等分支上的分支,不等于寄存器上的分支,小于或等于零的分支,大于或等于零的分支等等……所有分支指令仅使用两个操作数还有一个条件.如果突然在if语句中遇到多个条件,会发生什么情况.

MIPS provides branching instructions like branch on equal, branch on not equal to register,branch on less than or equal to zero, branch on greater than or equal to zero and so on... all the branching instructions use only two operands and one conditions . What happens if we suddenly encounter multiple conditions in if statement.

所以问题是如何为以下代码编写MIPS代码:

So the question is how can one write a MIPS code for :

if( (a<b) & ( b>c ) || (c==d)) {

}
else 
{

 }

请在if语句中提供这种多种条件的帮助.

Please help with this kind of multiple conditions in if statement.

推荐答案

您可以重写:

if( (a<b) && ( b>c ) || (c==d)) {

}

喜欢这个:

bool altb = a < b;
bool bgtc = b > c;
bool ceqd = c == d;
bool and1 = altb && bgtc;
bool condition = and1 || ceqd;
if (condition) {
} else {
}

这是大多数编译器将如何在if语句中评估复杂条件的方式.这种方法比将许多条件分支链接在一起要快得多.

This is how most compilers will evaluate a complex condition in an if statement. Doing it this way is also much faster than chaining a lot of conditional branches together.

这篇关于如果在MIPS中,则存在多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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