Bitwise Rotate Right ->
CassLan
Posts: 586
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...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
Method 2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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