메인 콘텐츠로 건너뛰기
Knowledgebase
Home
Renesas Korea

(Code Examples) How can I execute a table jump? [2008/03/11]

Latest Updated:03/11/2008

Question:

(Code Examples)  How can I execute a table jump? [2008/03/11]

Answer:

Use the zero page indirect jump addressing mode. (Applicable instructions: JMP and JSR)
Specify 2 continuous bytes of memory (JUMP_ADDR) in the zero page area in the operand and jump to the address which is shown in the memory contents.
These memory contents are set by using the table (ADDR_TABLE).
Refer to the 740 Family Software Manual for details.

A sample code using the JSR instruction is shown as follows:



	.section Z	
	.org  $0040	

M_MODE:	.BLKB 1		; Index (0=MODE_1, 2=MODE_2, 4=MODE_3)
			; Since the jump destination address is
			; allocated in units of 2 bytes, 
			; the index data is 0, 2 and 4.
JUMP_ADDR:.BLKB 2		; The stored memories of the table jump
			; destination address


	.section P	
	.org  $F000	

	LDX  M_MODE	; Read index
	LDA  ADDR_TABLE,X	; Store the low-order address of the jump destination
			; to the memory
	STA  JUMP_ADDR	
	INX	
	LDA  ADDR_TABLE,X	; Store the high-order address of the jump destination
			; to the memory
	STA  JUMP_ADDR+1	
	JSR  (JUMP_ADDR)	; Jump to each subroutine

	...

MODE_1:			; Execute when M_MODE=0
	RTS	
MODE_2:			; Execute when M_MODE=2
	RTS	
MODE_3:			; Execute when M_MODE=4
	RTS	


	.section TBL	
	.org  $FE00	

ADDR_TABLE:		
	.WORD MODE_1	
	.WORD MODE_2	
	.WORD MODE_3	

Note: When changing the JSR instruction to the JMP instruction, the RTS instruction is not necessary at the jump destination.

(#106923)

Suitable Products
3803H
3803L
3823
3850A
3858
38D2
38D5
7544
7545
7546
7547
7548
7549