使用相对指针寻址数据(x86-32 汇编器)

发布于 2024-09-19 10:46:44 字数 80 浏览 2 评论 0原文

我正在使用 32 位 x86 汇编器进行编写,并且不太确定如何寻址始终与代码具有相同关系的数据。我必须使用EIP来计算绝对地址,还是有更好的方法?

I'm writing in 32-bit x86 assembler, and I'm not quite sure how to address data that is always in the same relation to the code. Do I have to use EIP to calculate the absolute address, or is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话 2024-09-26 10:47:19

取决于操作系统。通常段寄存器DS(数据段)和CS(代码段)有不同的值。
因此,您可以使用 cs 前缀,例如:

mov    edx, cs:[eax]

在这种情况下,默认前缀是 ds 段寄存器。

Depend of OS. Normally have segment registers DS (data segment) and CS (code segment) different values.
So you can use cs prefix like:

mov    edx, cs:[eax]

In that case the default prefix is ds segment register.

千仐 2024-09-26 10:47:12

您可以使用与位置无关的代码:

   call @f
   dd 42 ; data
@@:
   pop eax ; eax contains offset of data
   mov eax, cs:[eax]

或将其与增量偏移量一起使用

   call base
base:
   pop ebp
   sub ebp, base ; to use small offsets, -128 to +127, and smaller instruction size
   ;....
   mov eax, cs:[ebp+dataN-base] ; dataN-base is called "delta-offset"
   ;....
data1:
   dd 100
   ;....
dataN:
   dd 200

You can use position-independent code:

   call @f
   dd 42 ; data
@@:
   pop eax ; eax contains offset of data
   mov eax, cs:[eax]

or use the same with delta-offsets

   call base
base:
   pop ebp
   sub ebp, base ; to use small offsets, -128 to +127, and smaller instruction size
   ;....
   mov eax, cs:[ebp+dataN-base] ; dataN-base is called "delta-offset"
   ;....
data1:
   dd 100
   ;....
dataN:
   dd 200
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文