|
-
Sep 25th, 2006, 10:41 AM
#1
Thread Starter
Hyperactive Member
[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!
Last edited by voidflux; Sep 28th, 2006 at 10:22 AM.
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
-
Sep 28th, 2006, 09:25 AM
#2
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".
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 28th, 2006, 10:19 AM
#3
Thread Starter
Hyperactive Member
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
#########################
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
-
Sep 28th, 2006, 10:23 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 28th, 2006, 10:53 AM
#5
Thread Starter
Hyperactive Member
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.
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
-
Sep 28th, 2006, 10:57 AM
#6
Re: [Resolved]MIPS32 (ASM) greater than or equal too, pseudo instruction question
It's not. The Alpha architecture has it, too.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|