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.
55 =0000000D temp1 EQU 0x0D ;temp1 VAR BYTE 56 57 =0000000E tempW EQU 0x0E ;tempW VAR WORD 58 =0000000E tempW_LSB EQU tempW 59 =0000000F tempW_MSB EQU tempW+1 60 61 62 07FF 0A00 RESET __PROGSTART ;PROGRAM Start NOSTARTUP 63 =00000000 __PROGSTART: 64 0000 0CF7 MOV FSR,#__TRISA 0001 0024 65 0002 0CFF MOV IND,#255 0003 0020 66 0004 02A4 INC FSR 67 0005 0020 MOV IND,W 68 0006 02A4 INC FSR 69 0007 0020 MOV IND,W 70 0008 0064 CLR FSR 71 0009 0010 JMP @Start 000A 0A0D 72 =0000000D ORG $+2 ; FOR DEBUGGER 73 74 75 =0000000D Start: ;Start: 76 77 000D 0C02 MOV temp1,#2 ; temp1 = 2 000E 002D 78 79 80 000F 0403 CLC ; temp1 = temp1 << 1 81 0010 036D RL temp1 82 83 0011 0C33 MOV __PARAM1,#Table & 255 ; READ Table + temp1, tempW 0012 0028 84 0013 0C00 MOV __PARAM2,#Table >> 8 0014 0029 85 0015 020D ADD __PARAM1,temp1 0016 01E8 86 0017 0603 ADDB __PARAM2,C 0018 02A9 87 0019 0209 MOV M,__PARAM2 001A 0043 88 001B 0208 MOV W,__PARAM1 89 001C 0041 IREAD 90 001D 002E MOV tempW_LSB,W 91 001E 02A8 INC __PARAM1 92 001F 0643 ADDB __PARAM2,Z 0020 02A9 93 0021 0209 MOV M,__PARAM2 0022 0043 94 0023 0208 MOV W,__PARAM1 95 0024 0041 IREAD 96 0025 002F MOV tempW_MSB,W 97 98 0026 0403 CLC ; temp1 = temp1 >> 1 99 0027 032D RR temp1 100 101 102 0028 020F MOV M,tempW_MSB ; READ tempW, temp1 0029 0043 103 002A 020E MOV W,tempW_LSB 104 002B 0041 IREAD 105 002C 002D MOV temp1,W 106 107 108 002D 0010 JMP @$ ;END 002E 0A2D 109 110 111 =0000002F DATA0: ;DATA0: 112 113 002F 0080 DW 128 ; DATA 128 114 115 =00000030 DATA1: ;DATA1: 116 117 0030 0081 DW 129 ; DATA 129 118 119 =00000031 DATA2: ;DATA2: 120 121 0031 0082 DW 130 ; DATA 130 122 123 =00000032 DATA3: ;DATA3: 124 125 0032 0083 DW 131 ; DATA 131 126 127 128 =00000033 Table: ;Table: 129 130 0033 002F DW (DATA0 & 255),(DATA0 >> 8),(DATA1 & 255),(DATA1 >> 8),(DATA2 & 255),(DATA2 >> 8),(DATA3 & 255),(DATA3 >> 8) ; DATA DATA0, DATA1, DATA2, DATA3 0034 0000 0030 0000 0031 0038 0000 0032 0000 131Bean.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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!