gcc - avr-gcc内联汇编: Jump to label with runtime offset

标签 gcc assembly label offset avr

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

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

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

最佳答案

请改用可重定位表达式修饰符。引用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. 

关于gcc - avr-gcc内联汇编: Jump to label with runtime offset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25005005/

相关文章:

c - 修改avr上函数的返回地址

assembly - 什么是参数推序

python - 是否可以将文本隐藏在 Tkinter 的按钮/标签内?

c# - 在标签名称中使用变量

c++ - gcc 4.8 或更早版本是否存在关于正则表达式的问题?

gcc - 用C代码(GCC)定义程序段

c++ - std::string::find_first_of 未返回预期值

c++ - 在 Fedora 14 上编译 C++ 程序时出现编译错误

c - 为什么 gcc 的开关生成的跳转比等效的函数调用更快但只有静态链接?

android - 如何在 MPAndroidChart 中隐藏值标签