Shop OBEX P1 Docs P2 Docs Learn Events
Is there some single instruction like WRC but setting ALL bits? — Parallax Forums

Is there some single instruction like WRC but setting ALL bits?

Hi,
for my Forth, at the moment I use WRZ and WRC to get a logic result as true or false onto the stack. However it would be better to have $FFFFFFFF for true instead of 1. I had a look into the list of instructions https://p2docs.github.io/p2_optable.html , but perhaps I have overlooked something?
WRZ followed by NEG is best then?
Thanks, Christof

Comments

  • You can use MUXC or MUXZ D,##$FFFFFFFF which also uses two longs. But if you need it more than once you can store the S operand in a register instead of using ##.

  • With the C flag, you can also use SUBX with the same register in both slots.

  • TonyB_TonyB_ Posts: 2,277
    edited 2026-04-20 11:24

    @"Christof Eb." said:
    Hi,
    for my Forth, at the moment I use WRZ and WRC to get a logic result as true or false onto the stack. However it would be better to have $FFFFFFFF for true instead of 1. I had a look into the list of instructions https://p2docs.github.io/p2_optable.html , but perhaps I have overlooked something?
    WRZ followed by NEG is best then?
    Thanks, Christof

    It can be done in one instruction for C and Z (latter needs a constant long).

    'a = 0/$FFFF_FFFF if c or z = 0/1
    
    'c
            subx    a,a        'or bitc    a,b
    'z
            bitz    a,b
    
    b       long    0 + 31 << 5
    
  • Thank you all very much!
    (((I must admit, that "Bits D[S[9:5]+S[4:0]:S[4:0]]" is rather obscure to me, the "+S[4:0]". Is this some kind of relative addressing of the bits? Why on earth?)))
    As cog registers are very precious at the moment, I am happy to use subx.

  • TonyB_TonyB_ Posts: 2,277
    edited 2026-04-20 15:19

    @"Christof Eb." said:
    Thank you all very much!
    (((I must admit, that "Bits D[S[9:5]+S[4:0]:S[4:0]]" is rather obscure to me, the "+S[4:0]". Is this some kind of relative addressing of the bits? Why on earth?)))
    As cog registers are very precious at the moment, I am happy to use subx.

    S[4:0] is the rightmost bit and S[9:5] is the number of extra contiguous bits to the left of that. If S[9:5] = 0 only one bit is changed as given by S[4:0]. A 9-bit #S can change up to 16 bits, hence need for register b above to change all 32 bits in a single 2-cycle instruction.

Sign In or Register to comment.