Why is it not possible to push a byte onto a stack on Pentium IA-32?

橙三吉。 提交于 2019-11-27 14:43:40

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

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!