2013-04-13 1 views
2

점프 테이블을 사용하여 작업을위한 메뉴를 작성하려고합니다. 모든 것은 나를 위해 괜찮아 보이지만 아래 코드는 작동하지 않습니다. Error in : invalid program counter value: 268501840MIPS에서 점프 테이블 사용하기 (JT 배열에서 레이블을 점프하는 법)

내가 268501840 그 라벨을 가기로되어 L1 라벨의 실제 주소와 코드 진수 주소를 알고 있지만 그 시점에서 다음 "주니어 $ S0"명령 화성 후 나에게 같은 오류를 제공 왜 이러는거야? 왜?

main: 
.data 
jTable: .word L0,L1,L2,L3,L4,L5,L6,default  #jump table definition 
msg: .asciiz "\nEnter Your Choice;\n [1] for build,\n [2] for insert,\n [3] for  find,\n [4] for findMinMax,\n [5] for delete,\n [6] for print\n [0] for Exit\nYour choice:#" 
.text 
userInteraction: 
li $v0,4   #print string 
la $a0,msg   #get string address 
syscall 

li $v0,5   #get a menu option from user(0 to 6) 
syscall 
move $s0,$v0   #get index in $s0 

sll $s0,$s0,2  #$s0=index*4 
la $t0,jTable  #$t0=base address of the jump table 
add $s0,$s0,$t0  #$s0+$t0 = actual address of jump label 

**jr $s0**   #jump to label 

L0: Todo 
j finish 
L1: Todo 
j userInteraction 
L2: Todo 
j userInteraction 
L3: Todo 
j userInteraction 
L4: Todo 
j userInteraction 
L5: Todo 
j userInteraction 
L6: Todo 
j userInteraction 
default: Todo 
j userInteraction 
finish: 
li $v0,10  #Exit 
syscall   #Exit 

답변

2

주소가 저장되어있는 배열로 건너 뛰려합니다. 의미가 없습니다. 당신은 jr 명령하기 전에 테이블에서 대상 주소를로드해야합니다 마이클 부하 워드 전화 오프셋 즉시로 jTable을 사용하여 적은 코드로 제안

sll $s0,$s0,2  #$s0=index*4 
la $t0,jTable  #$t0=base address of the jump table 
add $s0,$s0,$t0  #$s0+$t0 = actual address of jump label 
lw $s0,($s0)  # <-- load target address 
jr $s0    #jump to label 
1

당신은 같은 일을 수행 할 수 있습니다.

sll $s0,$s0,2  # $s0=index*4 
lw jTable($s0)  # load the target address 
jr $s0    # jump to the lable