8086微处理器的堆栈溢出
当堆栈已满并且我向其中推入一些东西时,8086 微处理器会发生什么行为?
What'll be the behaviour of the 8086 Microprocessor when the stack is full and even then I push something into it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 8086 上,PUSH 指令或隐式堆栈推送会将 SP 寄存器减 2,并将适当的数量存储在 SS:SP 处(即 16*SS+SP)。如果 SP 寄存器为 $0000,则数据将转到 SS:$FFFE。如果 SP 寄存器为 $0001,则数据的 MSB 将转到 SS:$0000,LSB 将转到 SS:$FFFF。处理器不会特别注意堆栈环绕。虽然堆栈环绕通常是一件坏事,但在 8086 上有一些情况,它可以被忽略,但不会影响任何事情。例如,如果 SS 指向其他任何东西都不需要的 64K RAM,并且一个永远不会退出的程序有时通过简单地调用“main()”而不重置堆栈来重新启动自身,则堆栈可以在不重置堆栈的情况下回绕。影响程序操作,因为所有有效地址计算都会以相同的方式绕回。
请注意,在 80386 及更高版本的处理器上,堆栈下溢行为发生了变化。 PUSH、CALL 等使用 32 位(或 64 位)地址计算,而不是 16 位,并且这些地址计算会包装到 $FFFFFFFF(或 $FFFFFFFFFFFFFFFF)而不是 $FFFF。
On the 8086, a PUSH instruction or implicit stack push will decrement the SP register by two and store the appropriate quantity at SS:SP (i.e. 16*SS+SP). If the SP register was $0000, the data will go to SS:$FFFE. If the SP register was $0001, the MSB of the data will go to SS:$0000 and the LSB will go to SS:$FFFF. The processor will not take any special notice of the stack wraparound. While stack wraparound would typically be a bad thing, there are some situations on the 8086 where it could be ignored at wouldn't affect anything. For example, if SS pointed to 64K of RAM that wasn't needed for anything else, and a program which was never going to exit sometimes restarted itself by simply calling "main()" without resetting the stack, the stack could wrap around without affecting program operation, since all effective-address calculations would wrap around the same way.
Note that on the 80386 and later processors, the stack-underflow behavior is changed. PUSH, CALL, etc. use 32-bit (or 64-bit) address calculations, rather than 16-bit, and those wrap to $FFFFFFFF (or $FFFFFFFFFFFFFFFF) rather than $FFFF.
8086 没有“保护模式”,因此没有“堆栈底部的保护页”,因此没有明确定义的异常。相反,您的推送将覆盖堆栈底部下方的任何代码或数据,如果执行该代码或使用该数据,这最终将(但不会立即)导致“未定义的行为”。
The 8086 has no 'protected mode', therefore no 'guard page at the bottom of the stack', therefore no well-defined exception. Instead your push will overwrite whatever code or data is below the bottom of the stack, which will eventually (but not immediately) result in "undefined behaviour" if that code is executed or that data is used.
没有尽头。我的意思是这些处理器中的堆栈具有相反的顺序(从右到左)。
因此它将一直持续到 ROM 块或内存末尾。这会导致处理器出现异常,处理器可能会自行软重置。
There is no end. I mean the stack in these processors has a reverse order (from right to left).
So it will go on up to a rom block or the end of memory. This causes an exception in the processor wich could soft reset itself.