为什么无法在 Pentium IA-32 上将字节压入堆栈?
我发现你不能直接将一个字节推入英特尔奔腾的堆栈上,有人可以向我解释一下吗?
我得到的原因是因为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在某些情况下,它会使堆栈指针无法完成其工作。例如,假设您有一个函数将一个字节压入堆栈,然后调用另一个函数。该调用最终将尝试将未对齐的返回地址写入堆栈,从而导致错误。
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.
它基于堆栈的创建方式:
来源: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:
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
您想要做的是使用位旋转操作码来旋转每个 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.
堆栈指针必须(出于某些优化原因)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).