检索数据在x86_64的 [英] Retrieving Data In x86_64

查看:128
本文介绍了检索数据在x86_64的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以检索从。长报表数据?
例如:

How can I retrieve data from a .long statement? For example:

.data 
data_items:
    .long 3,67,34,222,45,75,54,34,44,33,22,11,66,0

.text

.globl _main
    _main:
         movl    $0, %edi
         movl    data_items(,%edi,4), %eax

给出关于绝对地址没有被允许在x86_64的大型系列错误。我怎样才能访问这些数据?我是相当新的组装,所以我道歉,如果我的术语是混乱的。

Gives a large series of errors about absolute addressing not being allowed in x86_64. How can I access this data? I'm fairly new to assembly, so I apologize if my terminology is confusing.

编辑:我使用GNU汇编器/ GCC

I am using GNU Assembler/GCC

推荐答案

的问题是,你的数据在数据段和你的code是文本段。链接器设置为需要重新定位code,这意味着你不能使用绝对地址,因为你无法知道绝对地址,直到运行时。

The problem is that your data is in the data segment and your code is in the text segment. The linker is set up to require relocatable code, which means you can't use an absolute address, since you cannot know the absolute address until runtime.

要使用可重新定位code,你需要访问 data_items 作为一个从指令指针偏移,裂口

To use relocatable code, you need to access data_items as an offset from the instruction pointer, rip.

_main:
     movl    $0, %edi
     leaq    data_items(%rip), %rax
     movl    (%rax,%rdi,4), %eax

leaq 指令使用的指令指针,可在计算的偏移可获得 data_items 地址链接时。那么 MOVL 指令使用的地址为基准,为加载数据。请注意,我在处理中使用 RDI 。当你写 EDI 的高32位 RDI 被自动清零,所以这将工作未修改只要在 EDI 的值是无符号的。你可以使用 EDI EAX ,但会截断它们使用超过32位的地址,并将其编成$ C因为默认地址长度为64位$ C将更大。

The leaq instruction gets the address of data_items using an offset of the instruction pointer, which can be calculated at link time. Then the movl instruction uses that address as the base for loading the data. Note that I used rdi in the addressing. When you write to edi, the upper 32 bits of rdi are automatically cleared, so this will work unmodified as long as the value in edi is unsigned. You could use edi and eax, but that would truncate addresses which use more than 32 bits, and the compiled code would be larger since the default address size is 64 bits.

这篇关于检索数据在x86_64的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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