| | | Indexed call Does anyone have a clever way to do an indexed call on the 8051?
I can use jmp @a + dptr but I have common cleanup code that I want to execute after the call.
|
|
15-4-2004 21:52 Views: 2462 |
Kronulla |
| * | | RE: Indexed call Just call a routine that does an indexed jump,instead of jumping directly to it:
mov dptr, #JumpTable ; base of table
mov a,index ;index of entry in table
add a, acc ; multiply index by 3 as jumps are 3 bytes each
add a, index
call DoIndexedCall
...
DoIndexedCall:
jmp @a + dptr
... more (see whole posting) |
|
19-4-2004 16:03 Views: 2449 |
Splanky |
| * | | RE: Indexed call If you have a large jump table it can be better tojust store a table of addresses, rather than jumps, and get the address into dptr:
;-----------------------------------------------------------------------------
;
; Utility routine to perform an indexed call.
;
; Called with table base in DPTR, index (zero-based) in A
;
; The table must be a series of DW''s, NOT a jump table.
;
DoIndexedCall:
rl a ... more (see whole posting) |
|
19-4-2004 18:34 Views: 2431 |
ParticleMan |
| * | | RE: Indexed call - forgot to mention ... that you need to CALL this routine, not jump to it.
so...
mov a,5
mov dptr, #RoutineAddressTable
call DoIndexedCall
call SomethingElse
...
RoutineAddressTable:
dw Routine1
dw Routine2
..etc
The advantage of this approach is that the table is smaller, as only 2 ... more (see whole posting) |
|
19-4-2004 18:38 Views: 2461 |
ParticleMan |
| | | RE: Indexed call In indexed call can be done a little more efficiently using this (tested) code:
DoIndexedCall:
rl a ; multiply by 2 as table is words
mov b, a ; save index*2
movc a, @a + dptr ; get low byte of address
xch a, ... more (see whole posting) |
|
21-4-2004 22:28 Views: 2606 |
antix |
| | | RE: Indexed call I have used the following code fragment to implement both state machines and a simple interpreter. It is ideal when you have a relatively large number of small routines to be called based on an index when all routines can reside in one 256-byte page.
Uses 10 bytes of code plus 1 byte for each routine and takes 15 cycles including call/ret.
org ($ + 0FF00h) + 0100h ; start new 256-byte code page
routine_0:
< code for 1st routine >
... more (see whole posting) |
|
22-4-2004 0:25 Views: 2538 |
matthew |
| | | RE: Indexed call My solution is doesnt use the data pointer or any other register, but uses a jump table.
Uses and distroys the contents of the accumulator
mov a,#index_number
call Index_call
call what_ever
...
...
ret
Index_call:
rl a ;multply by 2
add a,# LOW Dis_mode_jump_table ;point to the jump table
push acc
mov a,# HIGH Dis_mode_jump_table ;point to the jump table
addc a,# 0 ;calculate 16bit address and store on stack
push acc
ret ;jump into the jump table
;
Dis_mode_jump_table:
;
ajmp dis_mode_0
ajmp dis_mode_1
ajmp dis_mode_2
regards
Mike Jenkinson |
|
16-2-2005 4:20 Views: 2210 |
mikejenx |