Assembler Stack Alignment (or better misaligned example with PUSH)

我的未来我决定 提交于 2019-12-13 13:23:25

问题


Well first I understand (or a I think that I understand) the problems of misaligned stack.

But I know (like a definition) that pushing a 16bit value to 32bit wide stack could cause a stack misaligned.

But the thing I dont understand, is how this could happend...since PUSH and POP check the D flag at the segment descriptor (so is 1 increments/decrements 32bits and is 0 16bits).

Suppose that D flag=1, should PUSH AX do a 32bits decrement? so its like I "miss" 16bits in the stack?

I am not sure that I understand this problem


回答1:


While both push and pop check the D-bit in the segment descriptor to determine the default operand size (i.e. 16 or 32/64 bits), it can be overridden with an operand size override 0x66.

If the D-bit is 0, then:

ff /6 

pushes 16 bits onto the stack

and

66 ff /6 

pushes 32 bits (or 64 if it's a 64-bit segment).

If the D-bit is 1, then the opposite is true.

In any case, ESP (or RSP or just SP, depending on the address size) is incremented or decremented by 2 (for 16 bit operations), 4 (for 32 bit operations) or 8 (for 64 bit operations).



来源:https://stackoverflow.com/questions/2302661/assembler-stack-alignment-or-better-misaligned-example-with-push

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