在 x64 程序集中订购 .data? [英] Order In .data in x64 Assembly?

查看:23
本文介绍了在 x64 程序集中订购 .data?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下汇编代码,我知道 .data 会朝着更高的地址增长,因此在运行代码后,内存看起来像:

Giving the following assembly code I know that .data grows towards higher addresses so after running the code the memory looks something like:

-
-
-
-
-
-
-
- (var3 here and up)
-
-
-
- (var2 here and up)
-
-
-
- (var1 here and up)

所以当他们问最后会在寄存器 rsp 中保存什么时,为什么蓝色选项是正确的?

So when they ask what will be saved in register rsp at the end why the blue option is the correct one?

这是我尝试解决它的方法:

Here is how I tried to solve it:

  • 在第一行,我们试图将 var3 的值保存在寄存器中,var3 的值是 var2 的值,即 -1,在第二行中,我们将其加 6,因此总共得到 5.

请注意,在上一个问题中,我被告知标签或变量没有 $ 之前表示其在内存中的值(数据),其中添加 $ 表示其在内存中的地址.

Please Note, In previous question I was told that label or variable with no $ before it means its value in memory (data) where adding $ means its address in memory.

推荐答案

var3的值为var2,即var2的地址..int, .quad, ... 指令总是将其操作数的地址存储到内存中.这也是您使用 .int 0 而不是 .int $0 的原因.所以你的推理是错误的.您还忘记考虑 pushq 指令对 rsp 寄存器内容的影响(推送 qword 将 rsp 减少 8).

The value of var3 is var2, i.e. the address of var2. The .int, .quad, ... directives always store the addresses of their operands into memory. Which is also why you have .int 0 instead of .int $0. So your reasoning is wrong. Also you forgot to account for the effect of the pushq instruction on the contents of the rsp register (pushing a qword decreases rsp by 8).

实际发生的事情:

mov var3, %rbx

var3 的内容被移动到 rbx 中.var3 保存着 var2 的地址.

The content of var3 is moved into rbx. var3 holds the address of var2.

lea 6(%rbx), %rsp

栈指针用rbx + 6加载.由于 rbx 持有 var2,所以现在是 var2+6.

The stack pointer is loaded with rbx + 6. As rbx holds var2, this is now var2+6.

pushq $0xffc8

一些东西被存储在堆栈中,将 rsp 减 8.rsp 现在保存了 var2-2.

Something is stored on the stack, decreasing rsp by 8. rsp now holds var2-2.

这篇关于在 x64 程序集中订购 .data?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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