Traditional Culture Encyclopedia - Hotel accommodation - Functions, operating procedures and characteristics of the stack

Functions, operating procedures and characteristics of the stack

Stack is actually two concepts in data results and a way to store data. Stack: random order; Stack: LIFO. To be useful, when writing code, sometimes there must be a prescribed order for data access, and this order is your own. Then, according to the characteristics of the usefulness of the program you wrote, ask questions in the order of heap, stack or queue: Why should the stack pointer SP be re-assigned when programming? Answer: Isn't this initialization?

Stack is a special storage area, its main function is to temporarily store data and addresses, which is usually used to protect breakpoints and sites. Its characteristic is to access data according to the principle of first-in and then-out, where the entry and exit refer to the operation of entering and exiting the stack.

Some units of 80C5 1 on-chip RAM can be used as stacks. There is an 8-bit stack pointer register SP, which is dedicated to indicating which unit of on-chip RAM is located at the top of the current stack. After the 80C5 1 single chip microcomputer system is reset, the initial value of SP is 07H, which means that information will accumulate from the 08H unit of internal RAM.

However, the stack area of 80C5 1 series is not fixed, and the stack area can be changed by changing the value of SP register by software. In order to avoid the working register area and the bit addressing area, the initial value of SP can be set to an address value of 2FH or more. If the CPU uses two sets of working registers in its operation, if the bit variable is not used, the initial value of SP should be at least 0FH or more; If bit variables are used, the initial value of SP should be at least 2FH or more; KeilC5 1 compiler will automatically calculate the initial setting value of SP, without programmer's care.