Shop OBEX P1 Docs P2 Docs Learn Events
Bit fill in PASM? — Parallax Forums

Bit fill in PASM?

DroneDrone Posts: 433
edited 2009-08-19 09:56 in Propeller 1
I have a long in a speed critical PASM program. If the value of the long is $00_00_00_00 I want it to stay that way. If the long is $00_00_00_01 I want to fill the LSByte with ones, so $00_00_00_01 maps to $00_00_00_FF. The values o of the long will only ever start with $00_00_00_00 or $00_00_00_01.

I can do this with if-else, but when if-else tests false it wastes four clock cycles. I would like to know if there's a single direct operation that can perform this. Something like a shift left that preserves the LSB. I can't seem to find a solution.

Thanks for any suggestions - David

Post Edited (Drone) : 8/18/2009 11:34:58 AM GMT

Comments

  • AleAle Posts: 2,363
    edited 2009-08-18 11:55
    it depends how many instructions are you willing to use, some methods could be:

    using a table

    
       movs  temp, my_long
       add   temp, #table
    temp
       mov  result, 0-0
    
    table  long 0
             long $00_00_00_ff
    
    
    



    with shifts, assuming result has the value already:

      ror  result, #1
      asr  result, #31
      shr result, #24
    
    



    another could be, if the value is in memory, this could be the shortest I can think of...

      test value, #1 wc
      muxc value, #$ff
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • ericballericball Posts: 774
    edited 2009-08-18 18:42
    The only way you can do it in a single instruction is if you set a flag in a previous instruction. The easiest would be the Z flag when the value is loaded into a register. Then you could use the flag to perform a conditional load #$FF.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-18 18:51
    Typically whatever instruction produced the value 1 or 0 could set the zero flag. Then you could do:

    MUXNZ value,#$FF
  • lonesocklonesock Posts: 917
    edited 2009-08-18 20:01
    Drone said...
    ...
    I can do this with if-else, but when if-else tests false it wastes four clock cycles. I would like to know if there's a single direct operation that can perform this. Something like a shift left that preserves the LSB. I can't seem to find a solution.
    ...
    RCL will load the C flag into multiple LSBs, but of course the flag must be set first.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • DroneDrone Posts: 433
    edited 2009-08-19 09:56
    Thanks for all the suggestions. Flags seem the way to go. Need to do some experiments and comparisons tonight. With your help I'm getting better with PASM, but still a long way to go =)

    Best Regards, David
Sign In or Register to comment.