关于堆栈段声明的基本问题
嘿,我刚刚开始学习汇编,这是我不明白的...
在堆栈段声明中,我们使用类似
TOS LABEL WORD
我知道 TOS 指的是堆栈顶部但不明白它后面的内容以及它是什么使用。帮助将不胜感激。
Hey, I am just starting to learn assembly and here's what i don't understand...
In the Stack Segment Declaration we use something like
TOS LABEL WORD
I know TOS refers to the top of the stack but don't understand what follows it and what's the use. Help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里所做的是定义一个标签(堆栈指针(SP)),其中包含堆栈顶部的地址。标签将始终包含最后一个值被推送的地址。
当您调用 PUSH 操作时,
寄存器或存储器的内容
位置被复制到堆栈中并且
SP 减少。
调用POP时,其中的内容
SP 指向(TOS)被复制到您施加它的任何寄存器或内存位置,并且 SP
调用
使用标记常量或变量的任何地址比以十六进制写入其在内存中的位置更容易。
编辑
它在 PUSH 上递减的原因是,随着每个新值被推送,堆栈在内存中向下增长。因此,如果您想将书籍放入一个盒子中,盒子底部的位置是 100,您可以在内存位置 100 处添加一本书。然后添加另一本书,它位于内存位置 99 处。内存位置 99 就成为 TOS。
编辑2
有些汇编器使用 LABEL 作为指令,有些则不使用。因此,在这种情况下,TOS 是“标签”,而 WORD 是数据类型。
所以你可以有:
或在其他汇编器中(我习惯的),简单地说:
起初我不知道你在什么上下文中使用它。这是我使用的资源: http://www.emu8086.com/assembler_tutorial/compatibility.html
What you are doing here is defining a label (stack pointer (SP)) that contains the address of the top of the stack. The label will always contain the address of where the last value was pushed.
When you call a PUSH operation, the
content of a register or memory
location is copied to the stack and
the SP is decremented.
When you call POP, the content of where
the SP points to (the TOS) is copied to whatever register or memory location you inflict it on and the SP
is incremented.
The use of labeling any address for a constant or variable is that it's easier than writing its location in the memory in hex.
EDIT
The reason why it is decrementing on PUSH is because a stack grows downward in memory as each new value is pushed. So if you think of putting books in a box, the location of the bottom of a box is 100, you add a book at memory location 100. Then add another and it's at memory location 99. Memory location 99 then becomes the TOS.
EDIT 2
Some assemblers use LABEL as a directive, some don't. So in this case TOS is the 'label', and WORD is the data type.
So you can have:
or in other assemblers (what I'm used to), simply:
At first I didn't know what context you were using this in. Here is the resource I used: http://www.emu8086.com/assembler_tutorial/compatibility.html