Assembly Language for Beginners

(Jeff_L) #1

1.14. CONDITIONAL JUMPS


locret_28:
jr $ra
or $at, $zero ; branch delay slot, NOP


Do not forget about thebranch delay slots: the firstMOVEis executedbeforeBEQZ, the secondMOVEis
executed only if the branch hasn’t been taken.


1.14.5 Conclusion.


x86


Here’s the rough skeleton of a conditional jump:


Listing 1.139: x86

CMP register, register/value
Jcc true ; cc=condition code
false:
... some code to be executed if comparison result is false ...
JMP exit
true:
... some code to be executed if comparison result is true ...
exit:


ARM


Listing 1.140: ARM

CMP register, register/value
Bcc true ; cc=condition code
false:
... some code to be executed if comparison result is false ...
JMP exit
true:
... some code to be executed if comparison result is true ...
exit:


MIPS


Listing 1.141: Check for zero

BEQZ REG, label
...


Listing 1.142: Check for less than zero using pseudoinstruction

BLTZ REG, label
...


Listing 1.143: Check for equal values

BEQ REG1, REG2, label
...


Listing 1.144: Check for non-equal values

BNE REG1, REG2, label
...


Listing 1.145: Check for less than (signed)

SLT REG1, REG2, REG3
BEQ REG1, label
...

Free download pdf