Shop OBEX P1 Docs P2 Docs Learn Events
How many ways to sample an input with PASM? — Parallax Forums

How many ways to sample an input with PASM?

StephenMooreStephenMoore Posts: 188
edited 2011-11-11 18:15 in Propeller 1
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

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-11-10 20:35
    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
    
  • StephenMooreStephenMoore Posts: 188
    edited 2011-11-10 21:05
    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."
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-10 21:15
    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.
  • StephenMooreStephenMoore Posts: 188
    edited 2011-11-10 21:41
    Can't says as to what I'd do with it neither.
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-10 21:46
    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.
  • StephenMooreStephenMoore Posts: 188
    edited 2011-11-10 22:00
    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 
    
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-10 22:14
    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
    
  • StephenMooreStephenMoore Posts: 188
    edited 2011-11-11 18:15
    Thanks for the help kuroneko.
Sign In or Register to comment.