堆栈段的用途(Purpose of stack segment)

堆栈段有3个主要的用途

1. 堆栈为函数内部声明的局部变量提供存储空间。按照C语言术语,这些变量被称为“自动变量”。

2. 进行函数调用时,堆栈存储与此有关的一些维护性信息,这些信息被称为堆栈结构,另外一个更常用的名字是过程活动记录。它包括函数调用地址(即所调用的函数结束后跳回的地方)、任何不适合装入寄存器的参数以及一些寄存器值的保存

3. 堆栈也可以被用作暂时存储区。有时候程序需要一些临时存储,比如计算一个很长的算术表达式时,它可以把部分计算结果压到堆栈中,当需要时再把它从堆栈中取出。

————————

< strong > stack segments have three main uses < / strong >

1. The stack provides storage space for local variables declared inside the function. According to C language terminology, these variables are called “automatic variables”.

2. When making function calls, the stack stores some maintenance information related to this. This information is called stack structure, and another more commonly used name is process activity record. It includes the function call address (i.e. the place to jump back after the called function is completed), any parameters that are not suitable for loading registers, and the storage of some register values

3. The stack can also be used as a temporary storage area. Sometimes the program needs some temporary storage. For example, when calculating a long arithmetic expression, it can push part of the calculation result onto the stack and take it out of the stack when necessary.