i'm trying to implement switch case in mips using jump table as an array of labels to jump to:
.data
JumpTable:
.word L0, L1, L2, L3
.text
.globl main
main:
la $t4, JumpTable # address of JumpTable
sll $t1, $s5, 2 # s5 is value of the variable witch we want to switch on it.
add $t1, $t1, $t4
lw $t0, 0($t1)
jr $t0
L0:
...
L1:
...
L2:
...
L3:
...
my question is, is there any way to do this for not sequential variables?(like 1,4,19,40)
You can add doubles to your table
.word L0, L0, L0, L0, L1, L2, L2, L2, L2, L2, L2, L3, ...
OR
use conditional branching. It depends on your intended application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With