Rotate left
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Rotate left
Hi Jan,
By rotate do you mean shift or do you need the bits to wrap around?
Here is some code to shift.
If you want to shift and wrap then you will likely have to do something like this.
Or to go the other way.
By rotate do you mean shift or do you need the bits to wrap around?
Here is some code to shift.
Code: Select all
var = var >> 1;
Code: Select all
count = 0;
while (count < shiftcount)
{
bitsave = var & 0x01;
var = var >> 1;
if (bitsave == 0x01)
var = var | 0x80;
count = count + 1;
}
Code: Select all
count = 0;
while (count < shiftcount)
{
bitsave = var & 0x80;
var = var << 1;
if (bitsave == 0x80)
var = var | 0x01;
count = count + 1;
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Rotate left
I think the sortest way to rotate left of the variable Ab will be:
asm MOVF gbl_FCV_AB, F
asm RLF gbl_FCV_AB, F
and rotate right:
asm MOVF gbl_FCV_AB, F
asm RRF gbl_FCV_AB, F
asm MOVF gbl_FCV_AB, F
asm RLF gbl_FCV_AB, F
and rotate right:
asm MOVF gbl_FCV_AB, F
asm RRF gbl_FCV_AB, F