Is there an ANDN equivalent in Spin2?

In PASM, the ANDN instruction is quite handy for clearing individual bit(s) in a register. I can't find a similar function in Spin2. I'm thinking about how you would change the output of an individual pin from 1 to 0.



  • ANDN exists also in the P2 instructions. Why do you think it's not there?

    But for individual pins there are much better instructions now:
    OUTH, OUTL sets the output High or Low
    DIRH, DIRL sets the direction of the pin
    DRVL, DRVH sets the direction and output with one instruction.
    The parameter is direct the pin number, this works for all 64 pins, not only for Port A or B.

  • JonnyMacJonnyMac Posts: 7,098
    edited 2020-11-19 - 17:17:29
    There are general instructions that will work on any register (though for IO, what Andy showed you is the most efficient).
    BITL    D,{#}S         {WCZ}
    BITH    D,{#}S         {WCZ}
    BITC    D,{#}S         {WCZ}
    BITNC   D,{#}S         {WCZ}
    BITZ    D,{#}S         {WCZ}
    BITNZ   D,{#}S         {WCZ}
    BITRND  D,{#}S         {WCZ}
    BITNOT  D,{#}S         {WCZ}

    Here's a simple bit-bang RX UART that takes in the bits LSB first -- using bitc (C has the new bit) and putting it where it belongs means no mask is needed, and no byte clean-up is required after.
                    mov       t1, bittix                            ' wait for middle of start bit
                    shr       t1, #1
                    addct1    bittimer, t1
                    mov       t3, #0                                ' clear workspace
    rx_byte         rep       #5, #8                                ' 5 (inst) x 8 bits
                     addct1   bittimer, bittix                      ' update bit timer
                     waitct1                                        ' let bit timer expire
                     testp    rxd                           wc      ' sample rx
                     shr      t3, #1                                ' prep for new bit
                     bitc     t3, #7                                ' add to result
    Note, too, that the RX pin is directly sampled into C using testp -- again, no mask required for IO access.
  • RaymanRayman Posts: 11,482
    edited 2020-11-22 - 13:27:18
    In Spin2 there are the equivalent of these assembly instructions ...

    Things like Pinhigh()

    But maybe &NOT would work in Spin2?
  • edited 2020-11-23 - 04:27:26
    The little bit I know about programming the propellor has been learned using PASM. Basically I know just enough spin to launch PASM code in a cog on the P1. When I started to look at Spin2 I couldn't find an andn equivalent and wondered if I had missed it somehow.

    As I become familiar with the P2 I'm learning that launching PASM code is not particularly hard so I can return to my usual methods.

    Thanks for your input.

  • There’s also the new inline assembly...

    With an org and end block.

    Makes using assembly in Spin2 easy.
  • JonnyMacJonnyMac Posts: 7,098
    edited 2020-11-23 - 15:59:27
    I'm prefer Spin but use a bit of PASM for speed when required. While the new PASM2 instruction set is much larger (by about 5x), much of it seems easier. As discussed earlier, bit manipulation is a lot easier in the P2 than in the P1.

    Inline PASM2 is my favorite thing about the P2. As Ray points out, it makes using small sections (that don't need to run in a cog) very easy. It also facilitates learning PASM2. I use this method for testing PASM2 instructions and code snippets:
    pub test_pasm2(dvalue, svalue, flagsin) : result, flagsout
                    testb     flagsin, #1                   wc              ' set flags
                    testb     flagsin, #0                   wz
                    rol       dvalue, svalue                wcz             ' instruction to test
                    mov       result, dvalue                                ' return modified value
                    bitc      flagsout, #1                                  ' return modified flags
                    bitz      flagsout, #0
Sign In or Register to comment.