C 用MIPS表达这句话

C 用MIPS表达这句话,c,mips,spim,C,Mips,Spim,我刚刚开始使用SPIM模拟器进行MIPS。有人能帮我转换一下这句话吗 if(as>47 && as<58) function(); else continue; if(as>47&&as我的MIPS有点生锈,如果不进行小的调整就无法正常工作,请提前道歉,但这应该能让您很好地了解您正在尝试做什么 (如果你发现这不起作用,请让我知道,以便我可以编辑帖子) #假设'as'在$s0中 li$t2,1#$t2=1 slti$t0,$s0,58#$t0=$s0

我刚刚开始使用SPIM模拟器进行MIPS。有人能帮我转换一下这句话吗

if(as>47 && as<58) function();
else continue;

if(as>47&&as我的MIPS有点生锈,如果不进行小的调整就无法正常工作,请提前道歉,但这应该能让您很好地了解您正在尝试做什么

(如果你发现这不起作用,请让我知道,以便我可以编辑帖子)

#假设'as'在$s0中
li$t2,1#$t2=1
slti$t0,$s0,58#$t0=$s0<58
addi$t1、$s0、1#$t1=$s0+1
slti$t1,47,$t1#$t1=47<$t1($s0+1)(sgti不存在)
和$t0、$t0、$t1#$t0=$t0&&t1
bne$t0,$t2,继续#如果($t0!=$t2)转到继续
功能:#标签是可选的。
#如果这两个条件都成立,bne将不会分支,因此我们将
#完成函数:并运行它拥有的任何代码。
#否则,我们跳转到cont:并跳过所有func代码。
# ...
续:#继续;;
# ...
请注意,现在,function()实际上不是一个函数。但是,您可以
jal function
并将该块驻留在其他地方。下面是一个示例

MIPS中的诀窍是,由于没有大于指令,因此必须使用相反的指令


记住,>的反面不是+1。在这种情况下,条件可以简化为
addi$t0,$s0,-48;sltiu$t0,$t0,58-48
# Assume 'as' is in $s0
li $t2, 1           # $t2 = 1
slti $t0, $s0, 58   # $t0 = $s0 < 58
addi $t1, $s0, 1    # $t1 = $s0 + 1
slti $t1, 47, $t1   # $t1 =  47 < $t1($s0 + 1) (sgti does not exist)
and $t0, $t0, $t1   # $t0 = $t0 && $t1

bne $t0, $t2, cont      # if ($t0 != $t2) goto cont

function: # Label is optional.
# If both conditions are true, the bne won't branch, so we will
# fall through to function: and run whatever code it has.
# otherwise, we jump to cont: and all the func code is skipped.
    # ...

cont: # continue;

    # ...