如何使用寄存器中存储的偏移量跳转到相对地址?

问题描述 投票:0回答:1

Intel/AMD 是这么说的:

mov rax, 0xabc
jmp rax

不等于:

jmp 0xabc

因为第一个由于寄存器的原因假设绝对跳转,而第二个假设相对跳转。我的问题是,如果我想做一个相对跳转,其中偏移量存储在诸如

rdi
之类的寄存器中怎么办?

我在SO中搜索了其他答案,但它们并没有那么有启发性。

assembly x86-64 low-level
1个回答
0
投票

您必须将基地址添加到偏移量以形成寄存器中的绝对地址,然后跳转到该地址。

例如

    ; jump table contains offsets relative to jump_base
    ; index into jump table is in rax
    lea rcx, [rel jump_table]
    mov ecx, [rcx+rax*4]
    lea rax, [rel jump_base]
    add rax, rcx
    jmp rax
jump_base:
© www.soinside.com 2019 - 2024. All rights reserved.