0

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 .ifs. 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.

Thom Wiggers
  • 6,938
  • 1
  • 39
  • 65

1 Answers1

1

I know that this doesn't directly answer your question, but are you aware of the fact that AVR registers are memory mapped at address zero? So you could use a runtime memory copy loop instead of this macro construct. Unbeknownst to me, you might of course have some other constraints that rule this option out.

Jester
  • 56,577
  • 4
  • 81
  • 125