I’m trying to move bits from starting register into eight consecutive registers. I’ve just started writing in assembly so I dont really know what to do.
I tried to use rol and lsr instructions. But my loop just reverses the bits. can i change the registry from r18 to r19 mid-loop?
.equ sequen = 0x10001011
ldi r17
ldi r16, 0x8
next: lsr r17
rol r18
;is there a way to move
;to next register, not
; inc its value?
dec r16
brbc 1, next
rjmp pc
As say Peter Cordes it is possible. For example like this
.equ sequen = 0b1000_1011
ldi r17, sequen
ldi r16, 0x8
ldi zl,18 ;Z (ZH:ZL) is used as indirect address register (pointer in C terminology)
ldi zh,0 ;this two instruction set Z to 18 - address for first value. See AVR memmory map for details
clr r0
next:
bst r17,0
bld r0, 0
st z+, r0 ;save result to register and increase address (18, 19, ...|
lsr r17
dec r16
brne next
rjmp pc