Need help with ASM code
I need help to get the best asm code for the following:
1) Declare 12-bit label values stored in program memory.
2) Index into the table of values with a 8-bit number.
3) Read the 12-bit value with iread.
4) Jump to the 12-bit value as a program memory location and start
execution.
I am new to the SX ASM so could i get help in making this as fast as possible.
cheers,
rich
[noparse][[/noparse]edit] Rich, I added a subject to your post. Bean.
Post Edited By Moderator (Bean (Hitt Consulting)) : 1/15/2008 12:50:31 PM GMT
1) Declare 12-bit label values stored in program memory.
2) Index into the table of values with a 8-bit number.
3) Read the 12-bit value with iread.
4) Jump to the 12-bit value as a program memory location and start
execution.
I am new to the SX ASM so could i get help in making this as fast as possible.
cheers,
rich
[noparse][[/noparse]edit] Rich, I added a subject to your post. Bean.
Post Edited By Moderator (Bean (Hitt Consulting)) : 1/15/2008 12:50:31 PM GMT
Comments
· Do you want a quick reply ? Or do you want the CODE to execute quickly ?
· Here is some output from SX/B to do it. I'm sure it not the as fast as it could be.
Bean.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
Post Edited (Bean (Hitt Consulting)) : 1/15/2008 1:58:11 PM GMT
cheers,
rich
but found this programming challenge too tasty to resist registering
just to answer.
A general way of doing a jump table with an SX in not easy.
But if you can live with a few constraints, it can be done fairly
efficiently.
1. You are limited to no more than 126 entries in your table
2. You must allocate a scratch file register; I will call it Scratch
;
; Call with index in W
;
Dispatch:
mov Scratch,W ; Double the index
add W,Scratch
add PC,W ; Jump to vector
page Entry0
jmp Entry0
page Entry1
jmp Entry1
page Entry2
jmp Entry2
:
:
:
Bill
the code can be modified to avoid the Scratch register:
mov !option, #%01011111 ; clear option.7 to map w into 01h
Dispatch
clc
rl wreg ; Note: you must use "wreg", SASM will generate wrong code when you use "w" here
add pc, w
page Entry0
jmp Entry0
;
;
;
As long as most jump targets are located in the same page where the dispatcher is located, you can even simplify the code but still handle cases where some code is outside the current page:
Dispatch
add pc, w
jmp Entry0
jmp Entry1
jmp Entry2
Entry0
;
;
Entry1
;
;
Entry2 ; This is an intermediate target - the remaining code for Entry2 is located in another page
page _Entry2
jmp _Entry2
;
;
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
True, but he did not specific which particular processor he was using. That option is not available with the SX-48 or SX-52. Or he may need access to the RTCC register.
mov W,Index
add W,Index
add PC,W
:
:
:
· The SX48 and SX52 also allow using WREG by setting the bit in the OPTION registers. Just for the book.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
At first thought, i would have looked at using the iread instruction so a jump table would not be needed.
When is the iread instruction used.
cheers,
rich
Better ways are available with macros:
http://www.sxlist.com/techref/ubicom/keymacs.src·
The LookupW macro conditionally·leaves out the snb and second mov when they are not needed.
The GotoW macro automatically compiles the most efficient possible jump table (not IREAD) given some supporting defines and sub macros. It's complicated to understand/explain, but it works very easily and always produces the best possible code.
There are also IF / THEN / ELSE·/ CASE and all that macros.. not that anyone would bother...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!