Son is working on a effects idea with a PICAXE.
Need a rll and rlr assembly commands (RoLlLeft, RolLRight).
example, 4 bits, barrel shifted left by 2 places:
before: 0110
after: 1001
or
before: 0011
after: 1100
That is Roll Left, 2 bits
With the 20M, which doesn't have << or >> commands, to make a 1 bit roll, he just multiplied by 2, if result was > 8, set result to 1. This worked fine.
Now he wants to jump 2 steps, since he got the PICAXE 20X2, and now has the << and >> operators (in addition to a ton more memory).
I'm thinking (4 bit barrel shift left):
x=0b00001100
x=x<<2 ;Shift left 2
y=x & f0 ;Get high nybble
x= x | y>>4 ; put LSB back to far right side
Is there a way to make this more efficient?
In C a function could be made for this, but it would only deal with char length digits (*char, bool dir, char bits)
Input?
Need a rll and rlr assembly commands (RoLlLeft, RolLRight).
example, 4 bits, barrel shifted left by 2 places:
before: 0110
after: 1001
or
before: 0011
after: 1100
That is Roll Left, 2 bits
With the 20M, which doesn't have << or >> commands, to make a 1 bit roll, he just multiplied by 2, if result was > 8, set result to 1. This worked fine.
Now he wants to jump 2 steps, since he got the PICAXE 20X2, and now has the << and >> operators (in addition to a ton more memory).
I'm thinking (4 bit barrel shift left):
x=0b00001100
x=x<<2 ;Shift left 2
y=x & f0 ;Get high nybble
x= x | y>>4 ; put LSB back to far right side
Is there a way to make this more efficient?
In C a function could be made for this, but it would only deal with char length digits (*char, bool dir, char bits)
Input?