Skip to main content
christiangaertner9
Associate
September 7, 2005
Question

jump to a calculated address

  • September 7, 2005
  • 2 replies
  • 784 views
Posted on September 07, 2005 at 06:47

jump to a calculated address

This topic has been closed for replies.

2 replies

christiangaertner9
Associate
September 7, 2005
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 III
September 7, 2005
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