Internet PLC Forum
General => Technical support => Topic started by: garysdickinson on December 21, 2012, 11:24:17 PM
-
Is it a know problem with Nano-10 +r73 that the RSHIFT command does not function as documented on actual hardware?
If I initialize DM[] as follows:
DM[1] = &H8000
DM[2] = &H8000
DM[3] = &H8000
DM[4] = &H8000
Then issue:
RSHIFT DM[1],4 ' shift one bit right DM[1..4]
This is what I see:
DM[1] = &HC000
DM[2] = &HC000
DM[3] = &HC000
DM[4] = &HC000
This is what I expected:
DM[1] = &H4000
DM[2] = &H4000
DM[3] = &H4000
DM[4] = &H4000
I am not seeing the least significant bit being shifted into the most significant bit of the lower numbered variable.
What I am seeing is a shift within each 16 bit register that is mostly a propagation of the signed bit.
For RSHIFT to be useful it CAN NOT be a 16-bit unsigned shift.
In the simulator the RSHIFT command executes as documented.
If I purchase a new Nano-10 is this problem resolved?
Gary D
-
Firmware version >= r78 corrected a bug in the RSHIFT command and that the new firmware should work as expected. In fact r78 now supports RSHIFT and LSHIFT of 32 bit variables (including DM[32]) across boundary so you can RSHIFT DM32[1],2 and it will shift correctly as it treats DM[1] & DM[2] as DM32[1] and DM[3] & DM[4] as DM32[2].
-
Thanks,
I am using a work-around for the firmware problem:
' This code is a work-around for the firmware problem.
'
' The following code is equivalent to this statement:
' RSHIFT DM[1],4
'
for j = 1 to 3 ' worry about carry in for first 3 registers
RSHIFT DM[j],1
if testbit(DM[j+1],0)
setbit DM[j],15 ' Carry-in will be a 1
else
clrbit DM[j],15 ' Carry-in will be a 0
endif
next
RSHIFT DM[j],1 ' No carry into most significant register
[/color][/font]
This will keep me working until I get new hardware,
Gary D.