Bit shifting left on P1 PASM
forthnutter
Posts: 7
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
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)
If you have other bits to check, you could create a mask (at the end of PASM code, before RES declarations)
then use AND to check it. With only one bit in the mask, C will contain the state of the tested bit.
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.
Indeed -- and I should have remembered that given I used the word 'test' in my reply!
Agree.