【发布时间】:2014-01-15 17:39:42
【问题描述】:
这个问题取自一本书汇编语言编程 将栈顶放入AX,不改变栈内容。 不使用 push 和 pop 怎么可能?
【问题讨论】:
-
假设 x86,在 AT&T 风格的 GAS 语法中:movl (%esp), %eax 或者更确切地说是 movw (%esp), %ax 如果你想要 16 位
标签: assembly
这个问题取自一本书汇编语言编程 将栈顶放入AX,不改变栈内容。 不使用 push 和 pop 怎么可能?
【问题讨论】:
标签: assembly
听起来像英特尔汇编。
mov ax, sp; moves the address of the top of the stack into ax.
mov ax, [sp]; moves the contents of the top of the stack into ax.
【讨论】:
[sp] 不是合法的寻址模式是对的,但更改为[esp] 使其与帖子的其余部分不一致。整个帖子应该是固定的,但不清楚原始发布者是否需要 16 位或 32 位解决方案。
mov bp, sp mov ax, [bp] 的 16 位答案作为 16 位代码的一种方法。
Assembly-Language-Programming-Organization-of-the-IBM-PC-1992 的第 158 页。这本书的这个版本是 8086。后来本书的另一个修订版涵盖了 386,但练习并不相同。我的猜测是这个问题是针对 16 位的