Re: A89: Invalid opcodes (was Re: Addressing)


[Prev][Next][Index][Thread]

Re: A89: Invalid opcodes (was Re: Addressing)




On Sun, Mar 19, 2000 at 01:44:15 -0500, Scott Dial wrote:
> 
> On that note... How do I get a68k to stop complianing about
> relocatability errors...
> 
> StartOfRoutines:
> r1:
> ...
> r2:
> ...
> 
> routineTable: dc.l r1-StartOfRoutine,r2-StartOfRoutines
> 
> That should give me offsets not absolute addresses... then later on I
> should be able to say:
>    lea StartOfRoutines(pc),a4
>    move.w #1,d0 ;Routine 1
>    mulu.w #4,d0
>    jsr (d0,a4)
> 
> But a68k doesn't like that...

One simple way to implement a jump table (as used by AMS for some switch()-
statments) is to do like this...

	; D0.W = routine number (0=first)
	add.w	d0,d0	; d0=d0*2
	move.w	JumpTable(pc,d0.w),d0 ; get offset '<routine>-JumpTable'
	jmp	JumpTable(pc,d0.w) ; do the jump
JumpTable:
	dc.w	r1-JumpTable
	dc.w	r2-JumpTable
r1:
	;...
r2:
	;...



Or, if the routines are (almost) equal in length (pretty unlikely however),
you can do this:
(But "don't try this at home kids" if you're not sure about it!)


ROUTINE_SIZE	= 8

ROUTINE	macro
	ifgt	*-(Routines+\1*ROUTINE_SIZE)
	; Is there an error directive? :)
	Argh!!! Routine larger than ROUTINE_SIZE!
	endif
	org	Routines+\1*ROUTINE_SIZE
	endm


	; D0.W = routine number (0=first)
	mulu.w	#ROUTINE_SIZE,d0
	; !!! change the above to shifts/adds if possible
	jmp	Routines(pc,d0.l)
Routines:
	;
	; * All routines (except the last) MUST be <=ROUTINE_SIZE bytes,
	;   including any 'rts'! The macro ROUTINE has a check for this.
	;
	; * The routines must be "declared" in ascending order!
	;   (Or else the macro ROUTINE fails!)
	;
	ROUTINE	0
	; code for routine 0
	rts
	ROUTINE	1
	; code for routine 1
	rts
	ROUTINE 2
	; etc...


/Johan


References: