So my excercise is to change order of bits so:
7 6 5 4 3 2 1 0
will be
3 2 7 6 1 0 5 4
I'm struggling with figuring this out. I'm trying to use rol method to rotate them so I would get 3 2 1 0 7 6 5 4 which would be at least a little bit closer. But the first bit that goes out of scope isn't carried through the second one is my example that I use is 0000 1111
code:
ldi r16,$0F - 0000 1111
rol r16 - 0001 1110
rol r16 - 0011 1100
rol r16 - 0111 1000
rol r16 - 1111 0000
rol r16 - 1110 000(0 - should be 1)
rol r16 - 1100 0001
UPDATE I've read in the excercise that we should flip bits 5 4 3 2 and then use shifts and rotate to get that order so here is my code
ldi r16,$0F
ldi r17,$3C
eor r16,r17
lsl r16
lsl r16
so r16 is 0000 1111 r17 is 0011 1100 then i use XOR gate to get in r16 0011 0011 and then i want to shift twice to the left with lsl so i get 0110 0110 but after I do the second shift I get: 0011 0001 instead of 1100 1100 and I'm not really sure why is that happening.
UPDATE 2 The previous code didn't work because the program didn't know what to do after executing last function so it went back to the beggining giving me bad result the solution is
end: rjmp endwhich forces program to infinitely jump to this line over and over again
ldi r16,$0F
ldi r17,$3C
eor r16,r17
lsl r16
lsl r16
end: rjmp end
bit 7goes tobit 5, etc. is that right? - WhatsUp