avr-gcc内联汇编:使用运行时偏移量跳转到标签

时间:2014-07-28 21:56:03

标签: gcc assembly label offset avr

在avr-gcc内联汇编中,如何跳转到标签加上运行时确定的偏移量?我以为我可以用它来实现像查找表这样的东西。

据我所知,可以通过将标签地址加载到Z寄存器,添加偏移量,然后使用ijmp指令来实现。但我不知道如何加载标签地址。这不起作用:

ldi r30,((label)>>0)&0xFF
ldi r31,((label)>>8)&0xFF

1 个答案:

答案 0 :(得分:2)

请改用relocatable表达式修饰符。引用binutils documentation

lo8
    This modifier allows you to use bits 0 through 7 of an address expression
    as 8 bit relocatable expression.
hi8
    This modifier allows you to use bits 7 through 15 of an address expression
    as 8 bit relocatable expression. This is useful with, for example, the AVR
    `ldi' instruction and `lo8' modifier.

    For example

              ldi r26, lo8(sym+10)
              ldi r27, hi8(sym+10)

pm_lo8
    This modifier allows you to use bits 0 through 7 of an address expression
    as 8 bit relocatable expression. This modifier useful for addressing data
    or code from Flash/Program memory. The using of `pm_lo8' similar to `lo8'.
pm_hi8
    This modifier allows you to use bits 8 through 15 of an address expression
    as 8 bit relocatable expression. This modifier useful for addressing data
    or code from Flash/Program memory.