开发者

Basic Question about Stack Segment Declaration

Hey, I am just starting to learn assembly and here's what i don't und开发者_Python百科erstand...

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.


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:

label1 LABEL WORD
.
.;code
.

or in other assemblers (what I'm used to), simply:

label1:
.
.
.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜