问题描述
这是一个简短的程序....
Here's a short program....
int main()
{
_asm
{
push al;
pop al;
pop al;
};
return 0;
}
哪个做得不多但是有效。但我认为不应该这样做,因为我将'al'推到堆叠上然后尝试将其拉出两次,因此堆叠起来。
似乎push实际上是将堆栈指针移动4个字节,而pop只是将它移回2,但是寄存器应该是一个字节,16bit的下半部分。发生了什么事?
我尝试了什么:
嗯,我试着在脑子里想了一下,但没有用。
which doesn't do much but it works. But I don't think it should, as I push 'al' onto the stack then try and pull it off twice, hence knackered stack.
It seems that the push is actually moving the stack pointer by 4 bytes, whereas the pop is only moving it back by 2, yet the register is supposed to be a single byte, the lower half of a 16bit thing. What's going on?
What I have tried:
Well, I tried thinking about it in my head for a bit, but it didn't help.
推荐答案
看起来推送实际上是将堆栈指针移动4个字节,而pop只是将它移回2,但寄存器应该是一个字节,下半部分是16位的东西。发生了什么事?
It seems that the push is actually moving the stack pointer by 4 bytes, whereas the pop is only moving it back by 2, yet the register is supposed to be a single byte, the lower half of a 16bit thing. What's going on?
al register是1字节,所以 push 和 pop 正在移动堆栈指针 1个字节。
根据设计,堆栈指针会根据您选择的寄存器大小移动。你的职责是使所有堆栈操作保持一致。
使用调试器可以看到究竟发生了什么。
[]
[]
[]
al register is 1 byte, so push and pop are moving stack pointer 1 byte.
By design, stack pointer move accordingly with size of register you selected. Your duty is to make all stack operations consistent.
Use debugger to be able to see what happen exactly.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
这篇关于为什么我的筹码很奇怪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!