I have to implement a switch/case statement using a jump address table in MIPS64 to run it in winmips64. I have search around for how to do this but the solutions are for mips32 using pseudo instructions that are not supported in winmips64. This is the code that i have so far.
.data
F: .word 0
G: .word 10
I: .word 5
H: .word 15
J: .word 6
K: .word 4
prompt: .asciiz "Case: "
CONTROL: .word32 0x10000
DATA: .word32 0x10008
.text
main:
ld $s0, F(r0)
ld $s1, G(r0)
ld $s2, H(r0)
ld $s3, I(r0)
ld $s4, J(r0)
ld $s5, K(r0)
lwu $s6,CONTROL(r0)
lwu $s7,DATA(r0)
daddi $t0,r0,4; ascii output
daddi r1,r0,prompt
sd r1,($s7)
sd $t0,($s6)
daddi $t0,r0,8 ; read input
sd $t0,($s6)
ld $s5,($s7)
daddi $t2, $zero, 4
slt $t3 , $s5 , $zero # $t3 =1 if k < 0
bne $t3 , $zero , Exit # if k < 0 go to Exit
slt $t3 , $s5 , $t2 # Test if k < 4
beq $t3 , $zero , Exit # if k >= 4 go to Exit
dadd $t1 , $s5 , $s5
dadd $t1 , $t1 , $t1
;load into $t4 address of table
dadd $t1, $t1, $t4 # $t1 = address of JumpTable [k]
lw $t0, 0($t1) # $t1 = JumpTable [k]
jr $t0
L0: dadd $s0 , $s3 , $s4 # f = i + j
j print
L1: dadd $s0 , $s1 , $s2 # f = g + h
j print
L2: dsub $s0 , $s3 , $s4 # f = g - h
j print
L3: dsub $s0 , $s1 , $s2
print:
daddi r24,r0,1; integer output
sd $s0,($s7)
sd r24,($s6)
Exit:
halt