PASM version of LOOKDOWNZ?
JonnyMac
Posts: 9,556
In Spin I would do this:
This is what I'm doing in PASM -- is there a better (more effective/efficient) way?
setup := lookdownz(ch: %1100, %1110, %1101, %1111)
This is what I'm doing in PASM -- is there a better (more effective/efficient) way?
chloop and ch, #%11 ' keep 0..3
cmp ch, #0 wz
if_e mov setup, #%1100
if_e jmp #muxbits
cmp ch, #1 wz
if_e mov setup, #%1110
if_e jmp #muxbits
cmp ch, #2 wz
if_e mov setup, #%1101
if_e jmp #muxbits
mov setup, #%1111
muxbits

Comments
edited: sorry, left out the main jmp
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
The trick works great with the mux bits for the ADC0834, but not with the ADC0838 (as I can see now). I looked at the way SX/B compiles LOOKDOWN and came up with this PASM equivalent for the ADC0838; seems to work but is brute force. Is there a better way? Speed is not an issue at all.
mloop andn outa, csMask ' activate adc (/CS = 0) and ch, #%111 ' keep ch legal, 0 to 7 mov setup, #%11000 ' assume ch0 cmp ch, #0 wz ' test if_e jmp #muxbits mov setup, #%11100 ' assume ch1 cmp ch, #1 wz ' test if_e jmp #muxbits mov setup, #%11001 ' assume ch2 cmp ch, #2 wz ' test if_e jmp #muxbits mov setup, #%11101 ' assume ch3 cmp ch, #3 wz ' test if_e jmp #muxbits mov setup, #%11010 ' assume ch4 cmp ch, #4 wz ' test if_e jmp #muxbits mov setup, #%11110 ' assume ch5 cmp ch, #5 wz ' test if_e jmp #muxbits mov setup, #%11011 ' assume ch6 cmp ch, #6 wz ' test if_e jmp #muxbits mov setup, #%11111 ' must be ch7 muxbits or dira, dioMask ' make dio an outputI _think_ that should work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
As long as the bits just need order swapping then either lonesock's method or the method below will work... either way it comes out to the same number of instructions.
' setup ch Cflag mov setup, #%11 '%...11 %........_........_........_.....abc ? ror ch, #2 wc '%...11 %bc......_........_........_.......a c rcl setup, #1 '%..11c %bc......_........_........_.......a c ror ch, #31 wc '%..11c %c......._........_........_......ab a rcl setup, #1 '%.11ca %c......._........_........_......ab a ror ch, #31 wc '%.11ca %........_........_........_.....abc b rcl setup, #1 '%11cab %........_........_........_.....abc b▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 5/18/2009 10:13:03 PM GMT
It saves a few instructions, but the readability goes way down [noparse][[/noparse]8^)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Follow-up: I whipped up a quick test program and verified that it works, Jonathan; and, as setup starts clean, I could drop the AND.
Post Edited (JonnyMac) : 5/19/2009 12:47:37 AM GMT
movs lookup,ch add lookup,#table nop lookup mov setup,0-0 ... table long %1100,%1110,%1101,%1111Andy
Post Edited (JonnyMac) : 5/19/2009 1:23:14 AM GMT
yes, Ariba's approach is going to execute the fastest. The example that he gave though uses a reserved Spin variable 'lookup'
that might have been causing you some problems. Here is the same code demonstrating the LEDs on the DEMO board.
mov ch, #3 ' <-change this value from 0 to 3 movs look_up, ch add look_up, #table nop look_up movs setup, 0-0 '--------------------------------------------------------------------------------- ' This stuff for the LED's '--------------------------------------------------------------------------------- shl setup, #16 '<--Just to see it in on the LED's mov dira, LEDmask 'Make the LEDs an output mov outa, setup 'show the data with the LEDs '--------------------------------------------------------------------------------- EndlessLoop jmp #EndlessLoop table long %1100,%1110,%1101,%1111 '----------------------------------------------------------------------- LEDmask long %00000000_11111111_00000000_00000000 ch long 0 setup long 0▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (JonnyMac) : 5/19/2009 4:01:11 AM GMT
"mov ch, #3 ' <-change this value from 0 to 3"
Does this line of code point to third value from the left in the "#table" which is %1101?
"add look_up, #table"
I see this line of code points to the table correct?
Also if I wanted to make two tables then I could do this?
mov ch, #3 ' <-change this value from 0 to 3 movs look_up, ch add look_up, #table '<-change this from table to table1 nop look_up movs setup, 0-0 '--------------------------------------------------------------------------------- ' This stuff for the LED's '--------------------------------------------------------------------------------- shl setup, #16 '<--Just to see it in on the LED's mov dira, LEDmask 'Make the LEDs an output mov outa, setup 'show the data with the LEDs '--------------------------------------------------------------------------------- EndlessLoop jmp #EndlessLoop table long %1100,%1110,%1101,%1111 table1 long %0001,%0011,%0111,%1001 '----------------------------------------------------------------------- LEDmask long %00000000_11111111_00000000_00000000 ch long 0 setup long 0In fact this adds the table base address to the index to form the final element address (base+index).
If you want more than one table then simply change the base address (i.e. use a different one). You could also merge the tables and adjust the index accordingly. For example in your code fragment using index 4 and base table is equivalent to using index 0 and base table1.
I see what you are saying about the zero base 3 is the 4th entry.
So what you are saying is that index 4 ,base adress table is pointing to the same as index 0, base adress table1 which is %0001 this is because the longs are inline correct?
So as long as they are not seperated with a different long then the index is just added to the base adress of the first long table?
Exactly. You may want to consider using different tables anyway depending on what they are used for. Otherwise you get confused later (after a few month) when you review your code
Thanks for the help I believe I understand it now.
Ariba's code
movs lookup, ch add lookup, #table nop lookup mov setup, 0-0Beau's code
movs look_up, ch add look_up, #table '<-change this from table to table1 nop look_up movs setup, 0-0Sandy
shl ch, #2 mov setup, table shr setup, ch and setup, #11 ... table long 11_1101_1110_1100