我必须使用 MIPS64 中的跳转地址表来实现 switch/case 语句才能在 winmips64 中运行它。我已经四处寻找如何做到这一点,但解决方案是针对 mips32 使用 winmips64 中不支持的伪指令。这是我到目前为止的代码。
.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