Shop OBEX P1 Docs P2 Docs Learn Events
Bit shifting left on P1 PASM — Parallax Forums

Bit shifting left on P1 PASM

My goal was get the status bit 30 in a variable.
I used SHL instruction so it goes into C flag.

if W has a value 0x80000000

SHL W,#2 WC

The C flag would always equal 1
The Propeller Manual says the C flag is set equal to Value’s original bit 31.
Does that mean shift of the number of bits, except 0, would result in C equal to 1 because bit 31 was set at the start of instruction ?.
My mind was in 68000 mode, thinking the number of bits shifted would go into C flag would work, but no.

A work around was to do two shl
SHL W,#1
SHL W,#1 WC

Comments

  • Wuerfel_21Wuerfel_21 Posts: 4,686
    edited 2023-09-25 13:42

    The C flag is always set to the original MSB of the shifted register, even if your shift count is zero. (same applies to right shifts, except they give you the LSB)

  • JonnyMacJonnyMac Posts: 9,003
    edited 2023-09-25 14:08

    If you have other bits to check, you could create a mask (at the end of PASM code, before RES declarations)

    BIT30                   long      1 << 30
    

    then use AND to check it. With only one bit in the mask, C will contain the state of the tested bit.

                            and       t1, BIT30             wc, nr
    

    With NR, the tested variable is not modified.

  • @JonnyMac said:
    If you have other bits to check, you could create a mask (at the end of PASM code, before RES declarations)

    BIT30                   long      1 << 30
    

    then use AND to check it. With only one bit in the mask, C will contain the state of the tested bit.

                            and       t1, BIT30             wc, nr
    

    With NR, the tested variable is not modified.

    Thanks for that, I did not think of doing that way.
    I suppose the TEST instruction does the same thing.

  • Yes, TEST is identical to AND with NR flag. (conversely, you can write TEST with a WR flag to get AND). I find TEST easier to read.

  • JonnyMacJonnyMac Posts: 9,003
    edited 2023-09-25 15:34

    I suppose the TEST instruction does the same thing.

    Indeed -- and I should have remembered that given I used the word 'test' in my reply! :D

    I find TEST easier to read.

    Agree.

                            test      t1, BIT30             wc
    
Sign In or Register to comment.