X86_64-装配-为什么不位移64位? [英] X86_64 - assembly - Why displacement not 64 bits?

查看:73
本文介绍了X86_64-装配-为什么不位移64位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Intel x86_64指南第1卷,以刷新内存寻址的工作方式.

I am reading the Intel x86_64 guide vol.1 to refresh how memory addressing works.

还是

3.7.5指定偏移量

3.7.5 Specifying an Offset

内存地址的偏移量部分可以直接指定为静态值(称为位移),也可以通过由以下一项或多项组成的地址计算来指定:

The offset part of a memory address can be specified directly as a static value (called a displacement) or through an address computation made up of one or more of the following components:

•位移-8、16或32位值.

• Displacement — An 8-, 16-, or 32-bit value.

我在 Agner Fog的汇编指南中读到,与(r/e)ax寄存器一起使用时,可以进行64位绝对寻址.

I read in Agner Fog's assembly guide that 64-bit absolute addressing was possible when used with (r/e)ax register.

所以..

是否可以使用对64位地址进行jmp,mov和call(带有所有寄存器)的绝对寻址,或者是否必须继续使用Base +位移组合 ?

推荐答案

请注意,mov absolute_addr64, %rax 可用,并且以rax为目标.
mov $imm64, %reg可用于任何寄存器.
参见从64位地址加载到其他地址比rax注册.

Note that mov absolute_addr64, %rax is only available with rax as the target.
mov $imm64, %reg is available for any register.
See Load from a 64-bit address into other register than rax.

AMD设计AMD64架构时,他们基本上说2GB的 code 对每个人都足够了.

When AMD designed the AMD64 architecture, they basically said 2GB of code should be enough for everyone.

http://www.x86-64.org/documentation/abi.pdf 描述了小型,中型和大型代码模型.

http://www.x86-64.org/documentation/abi.pdf describes the small, medium, and large code models.

  • small:每个跳转,调用和内存位移的正常32bit相对位移. (已知所有符号都位于02^31 - 2^24 - 1之间).

medium:小代码,但数据部分分为两部分:常规部分和大部分(.ldatalrodata.lbss).

medium: small code, but the data section is split into two parts: regular and large (.ldata, lrodata, .lbss).

此模型要求编译器使用movabs指令 访问大型静态数据并将地址加载到寄存器中,但是 保留了小代码模型的优势,可用于 小数据和文本部分中的地址(对于 分支)

This model requires the compiler to use movabs instructions to access large static data and to load addresses into registers, but keeps the advantages of the small code model for manipulation of addresses in the small data and text sections (specially needed for branches)

默认情况下,只会将大于65535字节的数据放入大数据部分

By default only data larger than 65535 bytes will be placed in the large data section

  • 大:

  • large:

    要求编译器使用movabs指令,如 中等代码模型,甚至用于处理文本中的地址 部分.此外,分支时需要间接分支 到与当前指令指针的偏移量为 未知.

    The compiler is required to use the movabs instruction, as in the medium code model, even for dealing with addresses inside the text section. Additionally, indirect branches are needed when branching to addresses whose offset from the current instruction pointer is unknown.

    可以避免对文本的限制 通过分解程序在中小型模型中的部分 到多个共享库中,因此该模型仅是严格的 如果单个函数的文本大于 中等模式允许.

    It is possible to avoid the limitation on the text section in the small and medium models by breaking up the program into multiple shared libraries, so this model is strictly only required if the text of a single function becomes larger than what the medium model allows.

  • 中型PIC需要movabs / lea / add生成具有大于32位位移的RIP相对地址.

    Medium PIC needs to movabs / lea / add to generate RIP-relative addresses with larger than 32bit displacements.

    大型PIC也需要使用它来处理全局偏移表和过程链接表.

    Large PIC needs that for addressing the global offset table and procedure linkage table, too.

    这篇关于X86_64-装配-为什么不位移64位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆