BSS segment: BSS segment (BSS segment) usually refers to an area of memory that is used to store uninitialized global variables in the program. BSS is the abbreviation for English block Started by symbol. BSS segments belong to static memory allocations.
Data segment: Data segment usually refers to an area of memory that is used to hold the initialized global variables in the program. The data segment belongs to static memory allocation.
Code Snippets: Code segment/text segment usually refers to an area of memory that is used to store program execution code. The size of this area is determined before the program runs, and the memory area is usually read-only, and some schemas allow the code snippet to be writable, which allows the program to be modified. In a code snippet, it is also possible to include some read-only constant variables, such as String constants.
Heap: A heap is used to store a dynamically allocated memory segment in a process run, which is not fixed in size and can be dynamically expanded or scaled down. When a process calls a function such as malloc to allocate memory, the newly allocated memory is dynamically added to the heap (heap is expanded), and freed memory is removed from the heap when memory is freed (heap is scaled down).
Stack: Stacks are also called stacks, which are local variables that are temporarily created by the user's program, that is, the variables defined in the parentheses "{}" (but not the variables that are static declarations, static means that the variables are stored in the data segment). In addition, when a function is called, its arguments are also pressed into the process stack that initiates the call, and the return value of the function is stored back to the stack when the call ends. Due to the advanced first-out features of the stack, the stack is particularly handy for saving/recovering call sites. In this sense, we can think of the stack as a memory area where temporary data is stored and exchanged.
A program is essentially composed of BSS, data, and text segments three.
Such a concept, do not know where the initial origin of the provisions, but in the current computer programming is very important a basic concept. It is also very important in the design of embedded system, which involves the allocation of memory size and the size of storage unit in the runtime of embedded system.
In an architecture that uses segment memory management (such as Intel's 80x86 system), the BSS segment (Block Started by Symbol segment) usually refers to a chunk of memory that is used to hold uninitialized global variables in the program, and generally the BSS segment will be zeroed when initialized. The BSS segment is a static memory allocation, where the program is zeroed out at the outset.
For example, after a program such as C has been compiled, the initialized global variable is saved in the. Data segment, and the uninitialized global variable is saved in the. BSS segment.
In "Programming ground up" the explanation for. BSS is: There is another section called the. BSS. This is a section of the data, except that it doesn ' t take up space in the executable.
Both the text and data fields are in the executable file (typically cured in an embedded system in an image file) and are loaded from the executable, while the BSS segment is not in the executable file and is initialized by the system.
1 Preface
There has been a specious understanding of the RO,RW and Zi data described in the ARM system, this period of time on its careful understanding of some, found some rules, understand some of the books before some but do not understand things, I think there are many people also have and I the same confusion, so will my some about the RO, RW and Zi's understanding of writing, hope to be helpful to everyone.
To understand ro,rw and Zi, you need to understand the following knowledge first.
2 Composition of ARM programs
The "arm program" here refers to the program being executed in the arm system, not the bin image (image) file that is stored in the ROM, which is a clear note of the difference.
An arm program consists of 3 parts: Ro,rw and Zi
RO is the instruction and constant in the program
RW is an initialized variable in the program
Zi is an uninitialized variable in the program
The above 3 points can be understood as:
RO is readonly,
RW is Read/write,
Zi is zero.
3 composition of ARM image files
The so-called arm image file refers to a bin file that is burned to ROM and becomes an image file. Use the image file to call it.
The image file contains RO and RW data.
The image file does not contain Zi data because the Zi data is 0 and is not necessarily included, as long as the program runs before the Zi data area is cleared 0. Instead, it wastes storage space.
Q: Why does the image have to contain RO and RW?
A: Because the directives and constants in RO and the initialized variables in RW are not "fabricated" like Zi.
4 execution process of ARM program
From the above two points can be known, burned to ROM image file and the actual runtime of the ARM program is not exactly the same. It is therefore necessary to understand how the ARM program gets to the actual running state from the image in ROM.
In fact, the directives in RO should have at least one of these features:
1. Move RW from ROM to ram because RW is a variable and the variable cannot exist in ROM.
2. Clear the Ram area where the Zi is located, because the Zi area is not in image, so the program needs to clear the corresponding RAM area according to the Zi address and size given by the compiler. Zi is also a variable in the same vein: The variable cannot exist in the ROM
In the initial stage of the program run, the instructions in the RO complete these two tasks before the C program can access the variables normally. Otherwise, you can only run code that does not contain variables.
BSS segment Data segment text segment heap heap and stack stack