Shop OBEX P1 Docs P2 Docs Learn Events
Reading bits — Parallax Forums

Reading bits

agimuhingagimuhing Posts: 39
edited 2011-01-24 15:36 in Propeller 1
How do you read the individual bits of a byte, word, or long?

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-01-24 15:07
    It depends on what you are trying to do, and also if you are using spin or pasm.
    If you are getting input from the pins, check the spin ina instruction - it can extract certain bits and put them into the lower bits.
    You can perform an "and" to extract the required bits.
    In pasm we can use the test instruction, or rotate into the carry position and use the carry if_c option.

    So, you need to describe what you are trying to achieve.
  • agimuhingagimuhing Posts: 39
    edited 2011-01-24 15:18
    I want to make a serial communication object
    I need it to be fast for what I'm planning to use it for (too difficult to describe, but it involves USB) so most of it will be in pasm

    I know how to extract bits but I'm wondering if there is any special assembly instruction that can do this
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-24 15:36
    As Clusso pointed out, you can use the C flag in PASM. To give you an example, I wrote this code that sends 16 bits to a DAC. The value is passed to the routine as 16 bits. The first thing the subroutine does is shift it left to move bit15 to bit31. Inside the loop a rotate instruction moves the bit31 into the C flag which is used to control the output.
    setdac                  shl     aout, #16                       ' move bit15 to bit31
                            mov     tmp1, #16                       ' shift 16 bits
    
                            andn    outa, smask                     ' sync low
    
    :loop                   rcl     aout, #1                wc      ' move bit (MSB) to C
                            muxc    outa, dmask                     ' move C to DIN pin
                            andn    outa, cmask                     ' clock low
                            or      outa, cmask                     ' clock high
                            djnz    tmp1, #:loop                    ' more bits?
    
                            or      outa, smask                     ' sync high
    
    setdac_ret              ret
    
Sign In or Register to comment.