Shop OBEX P1 Docs P2 Docs Learn Events
Pasm - set a specific bit — Parallax Forums

Pasm - set a specific bit

Agent420Agent420 Posts: 439
edited 2009-09-10 19:04 in Propeller 1
Probably the Dumb Question Of The Day™


Say I have a register that contains the decimal number of a bit I want to set (0-31)...· What is the most efficient method to accomplish this?

I need to create a 1 bit mask·for later use.· X contains the bit # to set.· In this example, I reset the mask to 1 because I do not believe I will encounter a non-zero value.
                        mov     mask,#1                 '+ 4 reset pixel mask
                        mov     temp,x                  '+ 4 copy x to work   
                        and     temp,#31                '+ 4 calc pixel bit #
                        shl     mask,temp               '+ 4 set pixel mask

I'm guessing that if I needed to address a potential 0 value, I'd test and use the carry flag in a rotate, but I have limited clock cycles for this application.

Look good, or is there a better method?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • lonesocklonesock Posts: 917
    edited 2009-09-10 18:57
    I haven't tried it, but does ROL automatically use only the bottom 5 bits? If so the and $31 would be automatic.
    mov mask,#1
    rol mask,x
    
    



    I haven't tried it, though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-10 18:59
    You don't need the and, and so you can dispense with temp. The shl only uses the lower five bits of the source.

    -Phil
  • Agent420Agent420 Posts: 439
    edited 2009-09-10 19:04
    I should have prefaced that my x value could well be > 31, but I do another shift elsewhere to calculate that value to be used as an offset.

    Nonetheless, I did not realize the shift and rotate operations were limited to the lower 5 bits.· Thanks - that will give me a few more cycles ;-)

    Thanks! cool.gif
    :read_x                 rdlong  x, idx                  '+ 8 read x coord
                            mov     mask,#1                 '+ 4 reset pixel mask
                            shl     mask,x                  '+ 4 set pixel mask
                            shr     x,#5                    '+ 4 divide x by 32 = offset
    :xoff                   mov     xoff,x                  '+ 4 store offset
    :mpix                   mov     mpix,mask               '+ 4 store pixel
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (Agent420) : 9/10/2009 7:12:12 PM GMT
Sign In or Register to comment.