Original post address posted by gavinkwoe
The RO, RW, and Zi data described in the arm system have a similar and non-existent understanding. During this time, we have carefully understood it and found some rules, I have understood some things that I did not understand in my previous books. I think many people may also be confused with me, we hope to help you understand RW and Zi.
To learn about ro, RW, and Zi, you must first understand the following knowledge:
Arm Program CompositionThe "arm program" mentioned here refers to the program being executed in the arm system, rather than the bin image file stored in the Rom.
An arm program contains three parts: RO, RW, and Zi.
Ro is the instruction and constant in the program.
RW is the initialized variable in the program.
Zi is an uninitialized variable in the program.
The above three points can be understood:
Ro is readonly,
RW is read/write,
Zi is zero.
Arm image file Composition
The so-called arm image file refers to the binary file burned into the ROM and also becomes an image file. The following is called an image file.
The image file contains Ro and RW data.
The reason why the image file does not contain the Zi data is that the Zi data is 0 and does not need to be included. You only need to clear the region where the Zi data is located before running the program. It wastes storage space.
Q: Why must image contain Ro and RW?
A: The commands and constants in RO and the initialized variables in RW cannot be "born out of nothing" like Zi.
Arm Program Execution ProcessFrom the above two points, we can know that the image file burned to the Rom is not exactly the same as the actual running arm program. Therefore, it is necessary to understand how the arm Program reaches the actual running state from the image in the Rom.
In fact, commands in Ro should have at least the following functions:
1. Move RW from Rom to ram. Because RW is a variable, the variable cannot exist in Rom.
2. Clear all the ram regions where Zi is located. Because the Zi region is not in the image, the program needs to clear the desired Ram region based on the Zi address and size given by the compiler. Zi is also a variable. Similarly, the variable cannot exist in Rom.
At the initial stage of the program running, the C program can access the variables normally after the commands in RO Have completed these two tasks. Otherwise, only codes without variables can be run.
After talking about what Ro, RW, and Zi are, I will give a few examples to illustrate Ro, RW, what does Zi mean in C.
1 ROLooking at the following two programs, there is a separate statement between them. This statement declares a character constant. Therefore, as we mentioned earlier, they should be only one byte different from RO data (the character constant is 1 byte ). Prog1:
# Include
Void main (void)
{
;
}
Prog2:
# Include
Const char a = 5;
Void main (void)
{
;
}
After prog1 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ================================
After prog2 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 61 0 96 0 grand totals
========================================================== ================================
Total Ro size (code + RO data) 1009 (0.99kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ================================
The information after the above two programs are compiled can be seen:
The RO of prog1 and prog2 contains two types of data: code and Ro data. Their only difference is that prog2's Ro data is 1 byte more than prog1. This is consistent with previous speculation.
If an instruction is added instead of a constant, the result should be the code data size difference.
2 RWLet's look at the two programs again. There is only one difference between them: "initialized variables". According to the previous instructions, initialized variables should be included in RW, therefore, the size of RW is different between two programs. Prog3:
# Include
Void main (void)
{
;
}
Prog4:
# Include
Char A = 5;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ================================
After prog4 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 60 1 96 0 grand totals
========================================================== ================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1009 (0.99kb)
========================================================== ================================
It can be seen that the difference between prog3 and prog4 is indeed only one byte between RW data. This byte is caused by an initialized variable ".
3 ZiLet's look at the two programs. The difference between them is an uninitialized variable "A". From the previous understanding, we can infer that there should be only a difference in the size of Zi between the two programs. Prog3:
# Include
Void main (void)
{
;
}
Prog4:
# Include
Char;
Void main (void)
{
;
}
After prog3 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 60 0 96 0 grand totals
========================================================== ================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 96 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ================================
After prog4 is compiled, the information is as follows:
========================================================== ================================
Code Ro data RW data Zi data debug
948 60 0 97 0 grand totals
========================================================== ================================
Total Ro size (codes + RO data) 1008 (0.98kb)
Total RW size (RW data + Zi data) 97 (0.09kb)
Total Rom size (code + RO Data + RW data) 1008 (0.98kb)
========================================================== ================================
The compiled results fully conform to the assumption that only the size of the Zi data is 1 byte different. This byte is caused by an uninitialized trans variable ".
Note: If a variable is initialized to 0, the variable will be processed in the Zi region in the same way as the volume of changes not initialized.
That is, in the arm C program, all uninitialized variables are automatically initialized to 0.
Summary:
1. commands and constants in C are compiled into Ro data.
2. The variable in C that is not initialized or initialized to 0 is compiled with Zi data.
3. Variables initialized to non-0 values in C compile the RW Type data in the future.