Shift & Rotate with count > 31 - in Spin and assembly language
ksltd
Posts: 163
There's no documentation regarding the effect of any shift or rotate instruction when the shift amount is greater than 31.
The instructions are SHL, SHR, SAR, ROL, ROR
The corresponding Spin operators are <<, >>, ~>, <- and ->.
The assembly language documentation suggests that if the source operand is an immediate form, that only the five least significant bits are used. This would imply that a shift of 33 bits is really a shift of 1 bit when using the immediate form.
Is the same true of the dynamic form of the instructions or does a shift of more than 31 bits shift away the entire contents of Dest?
What about the semantics of the corresponding Spin operators?
For what its worth, the assembler doesn't generate an error for:
shr <any address>,#<value bigger than 31>
The instructions are SHL, SHR, SAR, ROL, ROR
The corresponding Spin operators are <<, >>, ~>, <- and ->.
The assembly language documentation suggests that if the source operand is an immediate form, that only the five least significant bits are used. This would imply that a shift of 33 bits is really a shift of 1 bit when using the immediate form.
Is the same true of the dynamic form of the instructions or does a shift of more than 31 bits shift away the entire contents of Dest?
What about the semantics of the corresponding Spin operators?
For what its worth, the assembler doesn't generate an error for:
shr <any address>,#<value bigger than 31>
Comments
SPIN uses PASM equivalents where appropriate. IOW same effect for these operators.
Why would that be desirable? Imagine e.g. a packed pin value long. Do you really want to copy it to a temporary for each value and apply a mask instead of just using it? Besides, using a register makes it rather tricky to know what's in there at runtime, so why bother treating immediates differently?
The "z< 32" results if $ffff_ffff if true; 0, otherwise. 'Works for positive z only, BTW.
If z can be negative,
-Phil
Uggh, it never occurs to me to look at the datasheet for the implementation to glean information about the architecture.
My point about the assembler is that it would be good for it to generate an assembly-time error for something like:
shr some_register, #47
Phil,
My question wasn't about how to program, it was about the definition of the behavior.
-Phil
Actually, I've a nagging suspicion that there was one architecture that had a signed-shift (ie the direction
of shift was encoded in the shift-amount register), but can't remember for sure.
-Phil