[Resolved]MIPS32 (ASM) greater than or equal too, pseudo instruction question
Hello everyone.
I'm trying to figure this questoin out, it says:
We want to tr4anslate the pseduo instruction "bge $s1, $s2, Lb1" into two real MIPS assembly instructions. Which one is correct.
Code:
A:
slt $t0, $s2, $s1
beq $t0, $zero, Lb1
B:
slt $t0, $s2, $s1
bne $t0, $zero, Lb1
C:
slt $t0, $s1, $s2
beq $t0, $zero, Lb1
D:
slt $t0, $s1, $s2
bne $t0, $zero, Lb1
slt stands for set on less than
bne means branch if not equal
beq means branch if equal
and bge is the pseudo instruction that means branch if greater than or equal.
I translated each of the following and none seem to be "if greather than or equal too" i only see, if greather than.
Code:
A:
slt $t0, $s2, $s1
if($s2 < $s1) $t0 = 1
else $t0 = 0
beq $t0, $zero, Lb1
if($t0 == 0) goto Lb1
B:
slt $t0, $s2, $s1
if($s2 < $s1) $t0 = 1
else $t0 = 0
bne $t0,$zero, Lbl
if( $t0 != 0) goto Lb1
C:
if($s1 < $s2) $t0 = 1
else $t0 = 0;
if($t0 == 0) goto Lb1
D:
if($s1 < $s2) $t0 = 1
else $t0 = 0
if($t0 != 0) goto Lb1;
None of these seem to work, but B looks like it operates as the branch if $s1 > $s2, but not greather than or equal to. ANy help would be great!
thanks!
Re: MIPS32 (ASM) greater than or equal too, pseudo instruction question
Solution C is correct. It's a simple question of comparison equivalencies: a < b == not(a >= b), therefore "jump if not $s1 less than $s2" is the same as "jump if $s1 greater than or equal to $s2".
Re: MIPS32 (ASM) greater than or equal too, pseudo instruction question
Thanks CornedBee,
I did these lastnight I think they are all correct, I wasn't thinking when I first looked at them.
Code:
###############################
Branch Greather than or Equal
If s1 >= $s2 goto Lb1
bge $s1, $s2, Lb1
slt $t0, $s1, $s2
beq $t0, $0, Lb1
#########################
########################
Branch Greather than
if s1 > s2 goto Lb1
bgt $s1,$s2, Lb1
slt $t0, $s2, $s1
bne $t0, $0, Lb1
#######################
##########################
Branch Less than or Equal
if s1 <= s2 goto Lb1
ble $s1, $s2, Lb1
slt $t0, $s2, $s1
beq $t0, $0, Lb1
########################
########################
Branch less than
if s1 < s2 goto Lb1
blt $s1,$s2, Lb1
slt $t0, $s1, $s2
bne $t0, $0, Lb1
#########################
Re: [Resolved]MIPS32 (ASM) greater than or equal too, pseudo instruction question
I don't think $0 is correct for a numeric constant, but aside from that, yes.
Re: [Resolved]MIPS32 (ASM) greater than or equal too, pseudo instruction question
In MIPS 32, $0 stands for $zero register which is hard wired to 0 and can never be changed. Its like how you can write $2 which is equal to $v0 and register $8 == $t0 but these of course can be loaded with different values while $0/$zero cannot, i'm not sure if mips is the only ISA that does this.
Re: [Resolved]MIPS32 (ASM) greater than or equal too, pseudo instruction question
It's not. The Alpha architecture has it, too.