Home>Article> What is the stack in a computer?

What is the stack in a computer?

藏色散人
藏色散人 Original
2020-09-28 13:10:21 13741browse

The stack in the computer is also called a stack. It is a linear list with limited operations. It is a linear list that only performs insertion and deletion operations at the end of the list. This end is called the top of the stack. Relatively speaking, The other end is called the bottom of the stack; inserting a new element into a stack is also called pushing, pushing or pushing. It is to put the new element on top of the top element of the stack, making it the new top element of the stack.

What is the stack in a computer?

Recommended: "Programming Video"

Stack (stack) is also called a stack. A linear table with restricted operations. A linear table that restricts insertion and deletion operations only to the end of the table. This end is called the top of the stack, and the other end is called the bottom. Inserting a new element into a stack is also called pushing, pushing or pushing. It is to put the new element on top of the top element of the stack, making it a new top element; deleting elements from a stack is also called popping or pushing. Pop off the stack, which deletes the top element of the stack and makes its adjacent elements the new top element of the stack.

Basic concepts

To understand this concept, you must first understand the original meaning of "stack", so that you can grasp the essence. "Stack" refers to a place for storing goods or accommodation for passengers, which can be extended to warehouses and transfer stations. Therefore, when introduced into the computer field, it refers to a place where data is temporarily stored, so there are terms of entering and exiting the stack.

First of all, reading and inserting data content in the system or data structure stack (push and pop) are two different things! Pushing is to add data, and popping is to delete data. These operations can only be performed from the top of the stack, that is, the interface interface with the lowest address as a constraint, but reading the data in the stack is casual and there is no interface constraint. Many people misunderstand this concept and are confused about the stack. The system stack also serves as a media area for cross-component interaction in the computer architecture, that is, the communication channel between the CPU and the memory. The CPU only linearly reads execution instructions from the stack entry specified by the system for the application program we write. , using an image word to describe it is pipeline (pipeline, assembly line). For details on the internal interaction of the CPU, see the introduction to the concepts of EU and BIU.

Stack, as a data structure, is a special linear table that can only perform insertion and deletion operations at one end. It stores data according to the principle of first in, last out. The data that enters first is pushed to the bottom of the stack, and the last data is on the top of the stack. When data needs to be read, data is popped from the top of the stack (the last data is read out first). The stack has a memory function. During insertion and deletion operations on the stack, there is no need to change the bottom pointer of the stack.

A stack is a special linear list that allows insertion and deletion operations at the same end. The end that allows insertion and deletion operations is called the top of the stack, and the other end is the bottom. The bottom of the stack is fixed, and the top of the stack floats. When the number of elements in the stack is zero, it is called an empty stack. Insertion is generally called PUSH, and deletion is called popping (POP). Stack is also called first-in-last-out list.

The stack can be used to store breakpoints when a function is called. The stack is used when doing recursion!

The above definition is explained in classical computer science.

In computer systems, the stack is a dynamic memory area with the above attributes. The program can push data onto the stack or pop data off the top of the stack. In i386 machines, the top of the stack is located by a register called esp. The push operation causes the address at the top of the stack to decrease, and the pop operation causes the address at the top of the stack to increase.

The stack plays an important role in the running of the program. The most important thing is that the stack saves the maintenance information required when a function is called, which is often called a stack frame or activity record. Stack frames generally contain the following aspects of information:

1. The return address and parameters of the function

2. Temporary variables: including non-static local variables of functions and other temporary variables automatically generated by the compiler.

What is the stack in a computer?

The above is the detailed content of What is the stack in a computer?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn