Bitwise Rotate Right ->
Hi,
I have read the manual, but I can't seem to get rotate right to work:
Produces:
That would make sense to me for a shift-right...but not rotate right.
Am I doing something wrong?
Thanks,
Rick
I have read the manual, but I can't seem to get rotate right to work:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
byte loopcounter
word testpattern, testdone
OBJ
text : "tv_text"
PUB Main
text.start(12)
text.out(00)
testpattern := %0111111111111111
repeat loopcounter from 0 to 9
testdone := testpattern -> loopcounter
text.bin(testdone,16)
text.out(13)
Produces:
0111111111111111 0011111111111111 0001111111111111 0000111111111111 0000011111111111 0000001111111111
That would make sense to me for a shift-right...but not rotate right.
Am I doing something wrong?
Thanks,
Rick

Comments
Thanks kuroneko!
Rick
I believe this will do what you want...
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR byte loopcounter word testpattern OBJ text : "tv_text" PUB Main text.start(12) text.out(00) testpattern := %0111111111111111 repeat loopcounter from 0 to 9 testdone := testpattern -> loopcounter testdone_low |= testdone_high testdone &= $FFFF text.bin(testdone,16) text.out(13) DAT testdone long testdone_low word 0 testdone_high word 0▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 6/4/2009 2:50:29 PM GMT
I'd suggest:
testdone_high := testpattern
testdone_low:=testpattern
testdone := testdone -> loopcounter & $ffff
-Phil
Method 1
testdone := testpattern -> loopcounter '' rotate 'testpattern' into 'testdone' by 'loopcounter' number of bits ''testdone x000000000000000_0pxpxpxpxpxpxpxp testdone_low |= testdone_high '' OR highbyte of testdone into lowbyte of testdone ''testdone x000000000000000_xpxpxpxpxpxpxpxp '' Strip off upper 16 bits of testdone by ANDing with FFFF testdone &= $FFFF ''testdone 0000000000000000_xpxpxpxpxpxpxpxpMethod 2
testdone_high := testpattern '' Move testpattern into highbyte of testdone ''testdone pxpxpxpxpxpxpxpx_0000000000000000 testdone_low := testpattern '' Move testpattern into lowbyte of testdone ''testdone pxpxpxpxpxpxpxpx_pxpxpxpxpxpxpxpx testdone := testdone -> loopcounter & $ffff ''rotate 'testdone' by 'loopcounter' number of bits ''testdone xpxpxpxpxpxpxpxp_xpxpxpxpxpxpxpxp '' Strip off upper 16 bits of testdone by ANDing with FFFF ''testdone 0000000000000000_xpxpxpxpxpxpxpxp▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
One question ... if the rotate operation extends the operand to 32 bit, does it extend it sign correct? In this case method 1 would not work for 16 bit values starting with a MSB set to 1.
Post Edited (MagIO2) : 6/4/2009 9:32:56 PM GMT
"if the rotate operation extends the operand to 32 bit, does it extend it sign correct?" ... It's not extending it into 32 bit. The rotate is performed on a WORD, but only to read the WORD value. ALL of the bit manipulation is done within a 32-bit LONG internal register before it is written back to a variable. In this case the variable written back to was a LONG so all 32 bits were preserved. If it had been a WORD, the upper 16 bits would then be lost and the function would "act" like you were simply shifting the data and it would fall into nowhere, unless you shifted more than 16 bits. At that point you would start seeing the data once again if you were only writing the data back to a WORD variable.
Example
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 6/4/2009 10:25:22 PM GMT
Rick