1 what is the stack
Baidu said: The stack is a special linear table, a linear table that allows only insert or delete operations at one end of the table. The end of the table that allows insertion and deletion is called the top of the stack. The other end of the table is called the bottom of the stack. The current position of the top of the stack is dynamic, and the mark on the top of the stack is called the top pointer. When there is no data element in the stack, it is called an empty stack. The insert operation of the stack is usually referred to as pushing or pushing the stack. The delete operation of the stack is usually called unstacking or popping.
Easy to understand:
The inn, where temporary storage, the stack in the computer is mainly used to save temporary data, local variables and the return address of the interrupt / call subroutine program. The stack in the program is mainly used to store local variables in the function and save the register parameters. If you use the operating system, the stack may also store the context of the current thread. One principle for setting the stack size is to ensure that the stack does not underflow into data space or program space. When the CPU runs the program, it will automatically use the stack, so the stack pointer SP must be set before calling the C program.
The RAM RAM space storage rule of the CPU is generally segmented. From the address to the high address, the sequence is: program segment (.text), BSS segment, and there may be heap space above it, and then the topmost segment is the stack segment. This arrangement of the stack is determined by the characteristics of the stack. The initialization of the stack pointer SP is generally at the high address of the stack segment, which is the high address of the memory, and then the stack pointer is incremented (in fact, it is decremented).
The advantage of doing so is that the stack space is away from other segments, will not overlap with other segments, resulting in modification of other segments of data, causing unpredictable consequences, as well as the principle of setting the stack size, to ensure that the stack does not overflow to the data space Or program space. The so-called stack overflow, refers to the stack pointer SP grows to other segments of space, if the stack pointer grows down to other segment space, known as the stack overflow. Stack overflow will modify the value of other spaces, in serious cases can cause a crash.
2 stack pointer settings
Began to set the stack pointer in the internal RAM, because not every board has external RAM, and the size of the external RAM is also not the same, and if it is SDRAM, it needs to be initialized, the internal RAM starts to run is generally a small The bootstrapping program basically does not use the stack. Therefore, the stack is set in the internal RAM, but it is also necessary to use a large number of local variables.
On-chip 4K SRAM, SDRAM size 64M, from 0x30000000 to 0x33FFFFFF, when the program is running on-chip SRAM, the value of sp is set to 4096, when the program is running in SDRAM, sp is set to 0x34000000, when the program is in the internal SRAM Operation, if you have initialized SDRAM, you can also set the stack pointer to 0x34000000 to prevent stack overflow.
The overall role of 3 stacks
Save the scene;
Passing parameters: when assembly code calls C function, it needs to pass parameters;
Save temporary variables: non-static local variables including functions and other temporary variables automatically generated by the compiler;
1) Save the scene
On the scene, the meaning is equivalent to the crime scene. There are always some scenes on the scene that must be recorded. Otherwise, after being destroyed by others, you cannot recover the scene. The scene here is that when the CPU is running, some registers are used, such as r0, r1, etc. For these register values, if you jump directly to the subroutine without executing saving, then it is possible that It is destroyed because it also uses these registers for function execution. Therefore, before the function call, these registers should be kept temporarily on site (push push), etc. After the call to the execution of the function is completed and returned (pop pop), the scene is resumed. So that the CPU can continue to perform correctly.
Save the value of the register, generally use the push instruction, put the value of some corresponding register, one by one on the stack, push the corresponding value into the stack, which is the so-called push stack. Then when the subroutine to be called is executed, call pop again, assign the value of one of the stacks to the corresponding registers that you just used to push the stack, and pop the corresponding value from the stack. , the so-called stack. The register held therein also contains the value of lr (because the jump with bl instruction, then the value of the previous PC is in lr), then when the subroutine is finished executing, then the lr of the stack is The value pop comes out and is assigned to the PC so that the child function is returned correctly
2) Passing parameters
When C language is used to perform a function call, it is often passed to some parameters of the called function. For these C language-level parameters, when translated by the compiler into assembly language, it is necessary to find a place to store it, and let it be called. The function can be accessed, otherwise no delivery parameters are implemented. For finding a place to put it, there are two situations. In one case, there are no more than four parameters passed by itself, and the parameters can be transmitted through registers r0~r3. Because the values ​​of the corresponding registers have already been saved in the actions of the previous save scene, then at this time, these registers are free and can be used by us. Then we can put parameters. In another case, when there are more than 4 parameters, the register is not enough, so you have to use the stack.
3) Temporary variables are stored on the stack
Include non-static local variables of functions and other temporary variables that are automatically generated by the compiler.
Not only fashionable, but also protective. Our protective sleeves provide impact protection, shock absorption and a slim design. The Phone Case can give you peace of mind and provide better protection. If you keep your phone clean and scratch-free, you can also increase the resale value of your phone.
Design: The fit design makes your phone slimmer.
Protection: These Mobile Phone Case have been tested to withstand those accidental drops. The inner layer is made of Soft TPU rubber material, and the reinforced corners can absorb impact. High lips recess your screen and camera to provide additional protection. The outer hard shell is impact resistant.
Function: When all ports can be accessed, your phone can be used normally. The Cell Phone Case has molds for volume buttons and power buttons, so it is protected and you can still feel/use them.
If you want to know more about Mobile Phone Case products, please click the product details to view the parameters, models, pictures, prices and other information about Mobile Phone Case.
Whether you are a group or an individual, we will try our best to provide you with accurate and comprehensive information about the Mobile Phone Case!
Matte Phone Case, Marble Phone Case, Protective Case, Iphone Case, Transparent Phone Case, Protective Cover
Shenzhen Jianjiantong Technology Co., Ltd. , https://www.jjthydrogelprotector.com