Assume you have a
in $a0
, b
in $a1
and c
in $a2
then you would do
beq $a0, $a1, if
beq $a0, $a2, if
bgez $zero, else
if:
.. code if a=b or a=c
bgez $zero, endif
else:
.. code otherwise
endif:
Question
i'm trying to find a way to do something like bOR $a0, $a1, $a2 else
, something like if(a=b||a=c){blablabla}else{blabla}
in java, but i don't figure out a way to do it in mips32. Any idea?
Solution
Assume you have a
in $a0
, b
in $a1
and c
in $a2
then you would do
beq $a0, $a1, if
beq $a0, $a2, if
bgez $zero, else
if:
.. code if a=b or a=c
bgez $zero, endif
else:
.. code otherwise
endif:
OTHER TIPS
It's been ages since I did any assembly, but since no one has responded, here's what I remember. I hope you accept this answer, if for no other reason than that I'm re-living my worst nightmares for you.
To do any kind of logic in assembly, you'll need to do comparisons, followed by conditional jumps. So for instance, an if/else statement of the form:
if (a == b || a == c) {
cond1
}
else {
cond2
}
cond3
Would be translated as follows (pseudo-code):
cmp a,b
je cond1
cmp a,c
je cond1
...
cond2:
...
jmp cond3
cond1:
...
cond3:
...
Cmp compares values, and je is a conditional branch that jumps if the last comparison showed the values are equal. Basically, you're using gotos all over the place. Again, that's the pseudo-code, but you should easily find the MIPS analogs.
Speaking of which, I found this: http://jjc.hydrus.net/cs61c/handouts/loops4.pdf
x86 code, but it should give an idea.
cmp eax, ebx
je blablabla
cmp eax, ecx
jne blabla
blablabla: ; if a == b || a == c
;do your blablabla sutff here
jmp Continue
blabla: ; else
;do your blabla sutff here
Continue: