为什么无法在 Pentium IA-32 上将字节压入堆栈?

发布于 2024-08-28 09:00:45 字数 378 浏览 5 评论 0原文

我发现你不能直接将一个字节推入英特尔奔腾的堆栈上,有人可以向我解释一下吗?

我得到的原因是因为 esp 寄存器是可字寻址的(或者,这是我们模型中的假设)并且它必须是“偶地址”。我本以为递减某个 32 位二进制数的值不会扰乱寄存器的对齐,但显然我理解得不够。

我尝试了一些 NASM 测试,结果发现,如果我声明一个变量(bite db 123)并将其推入堆栈,esp 就会减少 4(表明它推入了 32 位?)。但是,“推字节咬”(抱歉我选择了变量名)将导致一种错误:

test.asm:10: error: Unsupported non-32-bit ELF relocation

在这个陷入困境的过程中,任何智慧之言将不胜感激时间。我是一年级本科生,很抱歉我在这方面的天真。

I've come to learn that you cannot push a byte directly onto the Intel Pentium's stack, can anyone explain this to me please?

The reason that I've been given is because the esp register is word-addressable (or, that is the assumption in our model) and it must be an "even address". I would have assumed decrementing the value of some 32-bit binary number wouldn't mess with the alignment of the register, but apparently I don't understand enough.

I have tried some NASM tests and come up that if I declare a variable (bite db 123) and push it on to the stack, esp is decremented by 4 (indicating that it pushed 32-bits?). But, "push byte bite" (sorry for my choice of variable names) will result in a kind error:

test.asm:10: error: Unsupported non-32-bit ELF relocation

Any words of wisdom would be greatly appreciated during this troubled time. I am first year undergraduate so sorry for my naivety in any of this.

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

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

发布评论

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

评论(4

把时间冻结 2024-09-04 09:00:45

在某些情况下,它会使堆栈指针无法完成其工作。例如,假设您有一个函数将一个字节压入堆栈,然后调用另一个函数。该调用最终将尝试将未对齐的返回地址写入堆栈,从而导致错误。

It'll make the stack pointer not able to do its job in some cases. for instance, lets say you had a function which pushed a byte onto the stack and then calls another function. The call will end up trying to write a misaligned return address onto the stack, resulting in an error.

你另情深 2024-09-04 09:00:45

它基于堆栈的创建方式:

地址大小属性
栈段决定栈
指针大小(16、32 或 64 位)。这
当前的操作数大小属性
代码段决定了数量
堆栈指针递减(2、4 或
8 字节)。

在非 64 位模式下:如果
地址大小和操作数大小
属性为32,即32位ESP
寄存器(堆栈指针)是
减 4。如果两个属性
16,16位SP寄存器(堆栈
指针)减 2。

来源:http://www.intel.com/ Assets/PDF/manual/253667.pdf

页。 4-320卷。 2B

编辑

只是想指出,手册中有关堆栈的部分很有趣,它将进一步解释如何创建堆栈段。

http://www.intel.com/Assets/PDF/manual/253665.pdf第

6.2章

Its based on how the stack was created:

The address-size attribute of the
stack segment determines the stack
pointer size (16, 32 or 64 bits). The
operand-size attribute of the current
code segment determines the amount the
stack pointer is decremented (2, 4 or
8 bytes).

In non-64-bit modes: if the
address-size and operand-size
attributes are 32, the 32-bit ESP
register (stack pointer) is
decremented by 4. If both attributes
are 16, the 16-bit SP register (stack
pointer) is decremented by 2.

Source: http://www.intel.com/Assets/PDF/manual/253667.pdf

pg. 4-320 Vol. 2B

Edit

Just wanted to point out also that an interesting read is the section on stacks in the manual, it will explain creating a stack segment further.

http://www.intel.com/Assets/PDF/manual/253665.pdf

Chapter 6.2

愁杀 2024-09-04 09:00:45

您想要做的是使用位旋转操作码来旋转每个 32 位内存位置,一次将 8 位放入寄存器中,直到旋转回起始位位置。现在您的 32 位寄存器中应该有 4 个 8 位数量并排排列。现在将其推入堆栈即可完成。

what you want to do is use the bit rotation opcodes to rotate through each 32-bit memory location, placing 8 bits at a time into the register until you have rotated back to the starting bit positions. now you should have 4 8-bit quantities lined up side by side in your 32 bit register. now push that onto the stack and you're done.

打小就很酷 2024-09-04 09:00:45

堆栈指针必须(出于某些优化原因)4B 对齐 -> 4B 对齐。它应该能被四整除(因此最后 2 位为零)。

The stack pointer must be (for some optimalization reasons) 4B aligned -> it should be divisible by four (and, therefore, have last 2 bits zero).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文