I've currently got this code:
// takes a table reference as an argument
.macro load_table_into_r0_to_r8
ldi ZL, low(2*@0)
ldi ZH, high(2*@0)
lpm r25, Z+
mov r0, r25
lpm r25, Z+
mov r1, r25
lpm r25, Z+
mov r2, r25
lpm r25, Z+
mov r3, r25
lpm r25, Z+
mov r4, r25
lpm r25, Z+
mov r5, r25
lpm r25, Z+
mov r6, r25
lpm r25, Z+
mov r7, r25
lpm r25, Z+
mov r8, r25
.endm
As you can see, a lot of really similar code is repeated.
It would be ridiculous if there isn't a way to write this in a shorter fashion, like with .irp
or maybe .if
s. However, I can't get that to work. For .irp
I tried this:
.irp i, 0,1,2,3,4,5,6,7,8
lpm r25, Z+
mov r\i, r25
.endr
While Atmel Studio does highlight .irp
(it doesn't other highlight everything that starts with a .
) it doesn't work: Invalid directive: '.irp'
See also my other, related question: MOV into a register specified by macro argument.