8086 SS and SP registers __ microcomputer principle

Source: Internet
Author: User

SS registers and SP registers:

According to the front stack of the introduction, I believe you are sure that the stack must have understood, not to mention, it is estimated that everyone is also a career roll for many years,

If the stack is not used, it is really tragic, so I will not be here to do a very detailed description of the stack,

However, the most basic introduction or want, after all, at the bottom of the words, not as convenient as the high-level language, you can directly a Stack on OK,

In the bottom of the stack is involved in the memory of the specific implementation.

I don't know, guys. I didn't mention how to find this stack when I introduced the knowledge of the stack on the top of this blog post.

I only mentioned that a stack is an advanced back-and-go operation, and that you can use "PUSH" and "POP" instructions,

And then just take a little bit of SS this register introduction,

Although we can easily define a stack in memory, why do we define such a stack?

Natural, is for the convenience of operation, simultaneously provides to the CPU use,

Since the CPU to use, naturally, the CPU must be based on a certain way to find this stack,

This requires the use of SS and SP registers.

At the same time, a stack is a piece of memory area, through the above introduction, we also know that if you want to accurately in a piece of memory to locate the memory unit (addressing),

We have to have a base address (that is, the segment address Left 4 digits) and the offset address, naturally, to be addressed in a stack, also need segment address and offset address,

And for a stack, we use the most of what is.

Of course it is the top of the stack, because only the top can be used to access data, so for a stack, we only need to have the top of the stack address and offset address,

And for the top of the stack address, it is stored in the segment register SS, and for the top of the stack offset address, it is stored in the SP register.

Remember, at any point in time, SS:SP is the top element of the stack.

In fact, the use of the stack is relatively simple, but to note that the 8086 CPU does not guarantee that our stack operation will not cross the line.

So we need to pay special attention to the stack's cross-border problem when using the stack.

When the push instruction is used to push 1 byte units into the stack, SP = SP-1; that is, the top element of the stack changes;

When the push instruction is used to push the 2-byte word unit into the stack, SP = sp–2; that is, the top element of the stack is also changed;

When using POP instructions to eject 1 byte cells from the stack, SP = sp + 1; The top element of the stack changes;

When using POP instructions to eject a 2-byte cell from the stack, SP = sp + 2; The top element of the stack changes;

The following is a Demo to introduce the use of the stack:

Assume cs:codes

codes SEGMENT
	
start:
    
    mov ax,1000h		; the first is to define a good stack of segment address
    mov ss,ax    
    mov ax,10h			; Then define the length of the stack (the initial point of the stack offset address is the length of the stack)
    mov sp,ax
    
    mov ax,0001h
    push ax
    mov ax,0002h
    push ax
    mov ax, 0003H
    push ax
    mov ax,0004h
    push ax
    mov ax,0005h
    push ax
    pop ax pop ax pop ax< C21/>pop ax
    POP ax
    
    
    MOV ah,4ch
    INT 21H
codes ENDS end
    START
And then we'll look at the stacks in memory structure diagram:

The execution of the statement is as follows:

First, let's look at the data in the stack when you haven't executed any of these instructions:

And then we'll follow the instructions in turn:

From the side of the screenshot can be seen has been set up ss:sp, that is, the stack has been set OK,

The following begins to press the data into the stack,

Because we press into the stack of data for Word data, that is 2 memory units, so each SP = sp–2;

After pressing 5 font data into the stack, we can look at the data in the stack,

So a good view of the structure in memory is shown below:

The following starts the stack operation

Because we pop up the stack when the data is Word data, that is 2 memory units, so, each SP = sp + 2;

After all 5 font data pops up in the stack, we can look at the data in the stack,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.