PDA

View Full Version : How many ways to sample an input with PASM?



StephenMoore
11-11-2011, 03:01 AM
I am kind of a beginner here. Just how many different ways are there to sample an input pin using PASM?

Here is one attempt I've used:



mov temp, ina
test temp, pir_mask wz
if_nz andn outa, pong_mask

pong_mask long 1 << PONG_LED
pir_mask long 1 << PIR
temp res 1


This works but I would like to know what the best way is (I know that I can not test ina directly for some reason).

There must be a quite a number of shorter version I would think.

SM

kuroneko
11-11-2011, 03:35 AM
Best is subjective (to me that is), have you tried this:

test pir_mask, ina wz
if_nz andn outa, pong_mask

pong_mask long |< PONG_LED
pir_mask long |< PIR

StephenMoore
11-11-2011, 04:05 AM
Works. But not if I swap pir_mask and ina on the test: why is that?

And is shorter too, thanks.

Any idea on what to do with this comment from pg 297 of the manual:

"Keep in mind that in Propeller Assembly, unlike in Spin, all 32 bits of INA are accessed at once unless the MUXx instructions are used."

kuroneko
11-11-2011, 04:15 AM
Works. But not if I swap pir_mask and ina on the test: why is that?
If ina is used in the destination slot of an instruction you access its shadow register which (unless modified) contains 0. Other candidates are par, cnt and phsx.


Any idea on what to do with this comment from pg 297 of the manual:

"Keep in mind that in Propeller Assembly, unlike in Spin, all 32 bits of INA are accessed at once unless the MUXx instructions are used."
Haven't a clue. Maybe it's in reference to the fact that you can't do value := ina[4] in PASM (as such). That said, SPIN would have to access all 32 bits as well and then pick a specific bit. The MUXx reference comletely escapes me.

StephenMoore
11-11-2011, 04:41 AM
Can't says as to what I'd do with it neither.

kuroneko
11-11-2011, 04:46 AM
Can't says as to what I'd do with it neither.
A big guess here. Could be referring to doing the test and then inserting the flag state (Z/C) into a register. Thing is, there are so many other ways of doing it. Not what I would bother muxc & Co with. Anyway, if something sounds odd just ask. The manual isn't free of errors.

StephenMoore
11-11-2011, 05:00 AM
That is exactly what led me to this thread... it seems like there are lots of ways but what is the simplest and shortest?

This seems overdone for some reason:



DAT
org 0


start mov dira, pong_mask
mov temp, ina
test temp, pir_mask wz
muxz temp, pir_mask
if_nz andn outa, pong_mask
jmp #$-4




pong_mask long |< LED_pin
pir_mask long |< PIR_pin
temp res 1

kuroneko
11-11-2011, 05:14 AM
DAT
org 0

start mov dira, #1
mov temp, ina
test temp, pir_mask wz
muxz temp, pir_mask

if_nz andn outa, pong_mask
jmp #$-3

pong_mask long |< LED_pin
pir_mask long |< PIR_pin
temp res 1


What is it supposed to do? ATM it only ever samples ina once (you better use jump labels instead of relative offsets, #$-3 is one short). Also, outa starts with 0 so the andn doesn't do a lot. So what are you after? Something like this:

DAT
org 0

start mov dira, pong_mask ' drive LED

:loop test pir_mask, ina wz ' PIR -> Z flag
muxz outa, pong_mask ' Z flag -> LED

jmp #:loop

pong_mask long |< LED_pin
pir_mask long |< PIR_pin

StephenMoore
11-12-2011, 01:15 AM
Thanks for the help kuroneko.