Home  
  Products  
  Ordering  
  Support  
  Forums  
  Search  
  Downloads  
  FAQ  
  About  
  Contacts  
22 May 2013 11:10:14

Latest News

Search Acqura
Subscribe to Acqura's Newsletter for information about Philips microcontrollers and smart coding tips.
Subscribe to our newsletter
First Time Visitor
Login
Register
There are 8 Guest users online.

Products
  Emulation Tools
    8xC51 Family
    LPC76x Family
    8xC51MX Family
    LPC900 Family
    Choosing an
    Emulator

  Programmers
  Adapters
  Bondouts/Spares
  Repairs
  Microcontroller Sales

Ordering
  Show My Cart
  Proceed to Checkout

Support
  Downloads
  Forums
  Links and Resources
  Data Sheets
  Technical Notes
  Testimonials
  FAQ
  Common Problems
  Repairs and Returns
  Contacting Us
  About Acqura

Take our Poll
When programming ARM microcontrollers, what is your preferred language?
Assembler
C
Pascal
Modula-2
Other
  
Free polls from Pollhost.com
Indexed call
This thread was started in the General Forum by user Kronulla on 15-4-2004 21:52
To add a posting to this thread, click on the message you wish to reply to. Your reply will be inserted at that point in the thread.
Topic Posted User
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.

Reply to this post
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)
Reply to this post
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)
Reply to this post
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)
Reply to this post
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)
Reply to this post
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)
Reply to this post
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
Reply to this post
16-2-2005  4:20
Views: 2210
mikejenx
Start new topic in the General forum
Show all topics in the General forum
Show all forums
Show all my postings
Show all threads added to since my last visit
Show all threads with no replies
info@acqura.com
Home

Last modified on
Tue Apr 20 19:53:16 CDT 2004
Copyright © 2008.
Acqura Systems
All rights reserved.