AVR (atmega8515) rjmp 相对不跳

AVR (atmega8515) rjmp doesn't jump relatively

Relative jump to an address within PC - 2K +1 and PC + 2K (words). In the assembler, labels are used instead of relative operands. For AVR microcontrollers with program memory not exceeding 4K words (8K bytes) this instruction can address the entire memory from every address location.

http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_RJMP.html的基础上,rjmp命令应该相对改变PC寄存器。但是我下面的代码跳转到了确切的地址(在本例中为地址为 0x00 的 ldi temp, low(RAMEND) 命令)

.include "m8515def.inc"

.def temp = r16


STACK_INIT:
    ; init stack pointer
    ldi temp, low(RAMEND)
    out SPL, temp
    ldi temp, high(RAMEND)
    out SPH, temp

TES:
    rjmp 0x00

END:
    rjmp END

我尝试将 rjmp 命令更改为 jmp 但 atmega8515 不支持该命令

我不知道这是因为配置还是其他原因。我正在使用 AVR Studio 4 构建和 运行 我的程序。有人可以解释一下吗?

这是意料之中的。为了方便汇编语言程序员,rjmp 操作采用绝对地址而不是相对地址。实际编译二进制机器码时会将绝对地址转换为相对地址,如果地址太远无法跳转会报错。

顺便说一下,您可以在操作数中使用 $ 符号。它是当前指令的地址。所以像 rjmp $+2 这样的东西会跳到下一条指令之后的两个字节。