cancel
Showing results for 
Search instead for 
Did you mean: 

jump to a calculated address

christiangaertner9
Associate II
Posted on September 07, 2005 at 06:47

jump to a calculated address

2 REPLIES 2
christiangaertner9
Associate II
Posted on September 07, 2005 at 05:00

Hello,

how do I have to realize a jump to a calculated address?

exp.

label_xyz

...

jump to label_xyz + offset

Regards,

Cristian

fggnrc
Associate II
Posted on September 07, 2005 at 06:47

Cristian, in assembler you can use these instructions:

segment 'ram0'

BYTES

offset_L DS 1

offset_H DS 1

segment 'rom'

WORDS

LD A,#label_xyz.L

ADD A,offset_L

PUSH A

LD A,#label_xyz.H

ADC A,offset_H

PUSH A

RET

Regards,

EtaPhi

BTW: the code fragment stores the offset in two bytes of ram.

If it is smaller, or if the jump destinations are all in the same page, some instructions can be removed.

However, I suggest you to use a function table:

JumpTable.w

DC.W Label_1

DC.W Label_2

DC.W Label_3

; X holds the index of the label where you need to jump

SLL X

LD A,({JumpTable+1},X)

PUSH A

LD A,(JumpTable,X)

PUSH A

RET