KEIL MDK View Code volume, Ram usage--ro-data, Rw-data, zi-data explanation

Source: Internet
Author: User

Source: KEIL MDK View Code volume, Ram usage--ro-data, Rw-data, zi-data explanation

KEIL RVMDK Post-compilation information

Program size:code=86496 ro-data=9064 rw-data=1452 zi-data=16116

Code is the amount of space that is consumed by the codes;

Ro-data is the size of Read only read-only constant, such as const type;

Rw-data is the size of the read-write variable that was initialized;

Zi-data is the size of a read-write variable (Zero Initialize) that is not initialized. Zi-data will not be counted as code because it will not be initialized;

In short, it is in the burning of the time is flash in the occupied space:Code + RO data + RW data

When the program runs, the chip internal RAM uses the space: RW data + ZI data

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

Source: The RO, rw, and Zi data sections in arm compilation

The composition of an arm program (a program being executed in an arm system, rather than a bin file saved in ROM)

An arm program consists of 3 parts: Ro segment, rw segment, and Zi segment.

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.

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.

The 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, the same way: The variable can not exist in ROM in the initial stage of the program, the RO instructions to complete the two work after the C program to access the variable normally. Otherwise, you can only run code that does not contain variables.

Said the above may be a little confused, ro,rw and Zi in the end is what, below I will give a few examples, the most intuitive to say what Ro,rw,zi in C mean.

1; Ro

Look at the following two procedures, they have a statement between them, this statement is to declare a character constant. So as we said before, they should only be one byte apart in the RO data (the character constant is 1 bytes).

#include <stdio.h> void main (void) {;}       //  #include <stdio.h>  constchar5void Main (void)  {      ;  

Prog1 compiled information is as follows: ================================================================================

Total RO Size (Code + ro Data) 1008 (0.98kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1008 (0.98kB) ================================================================== ==============

Prog2 compiled with the following information:

================================================================================

Total RO Size (Code + ro Data) 1009 (0.99kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1009 (0.99kB) ================================================================== ==============

The information after compiling the above two programs can be seen:

The Ro of Prog1 and PROG2 contains two types of data, code and RO. The only difference is that Prog2 's ro data is 1 bytes more than Prog1.  This is consistent with the previous speculation. If you add an instruction instead of a constant, the result should be a difference in the size of the code data.

2; RW

Also look at two programs, they are only one "initialized variable", according to the previous, the initialized variable should be counted in RW, so two programs should be RW size difference.

#include <stdio.h> void main (void) {;}       //  #include <stdio.h>  char5void main (void )  {      ;  


Prog3 compiled with the following information:

================================================================================

Total RO Size (Code + ro Data) 1008 (0.98kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1008 (0.98kB) ================================================================== ==============

Prog4 compiled with the following information:

================================================================================

Total RO Size (Code + ro Data) 1008 (0.98kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1009 (0.99kB) ================================================================= ===============

It can be seen that between Prog3 and Prog4 there is really only 1 bytes between RW data, which is the result of the initialization of a character variable "a".

3; ZI

Look at two programs, the difference between them is an uninitialized variable "a", from the previous understanding, it should be possible to speculate that the two programs should be only Zi size difference.

// Prog3: #include <stdio.h>   void Main (void)  {      ;  }   //  #include <stdio.h>  char  A;void main (void)  {      ;  }

Prog3 compiled with the following information:

================================================================================

Total RO Size (Code + ro Data) 1008 (0.98kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1008 (0.98kB) ================================================================= ===============

Prog4 compiled with the following information:

================================================================================

Total RO Size (Code + ro Data) 1008 (0.98kB)

Total RW Size (rw data + ZI data) (0.09kB)

Total ROM Size (Code + RO data + RW data) 1008 (0.98kB) ================================================================= ===============

The result of the compilation is completely speculative, with only the Zi data being 1 bytes apart. This byte is the result of an uninitialized character variable "a".

Attention:

If a variable is initialized to 0, the variable is treated in the same way as an uninitialized Zi in the region. That is: in ARM C programs, all uninitialized variables are automatically initialized to 0.

Summarize:

1; The instructions in C and the constants are compiled with RO type data.

2; A variable in C that has not been initialized or initialized to 0 is compiled with Zi type data.

3; A variable in C that has been initialized to a value other than 0 is compiled with the future RW type data.

Attached: compiler command for program (assuming C program named TST.C): Armcc-c-O tst.o tst.c

Armlink-noremove-elf-nodebug-info totals-info sizes-map-list aa.map-o tst.elf TST.O

The compiled information is in the Aa.map file.

Rom mainly refers to: NAND Flash,nor Flash

Ram mainly refers to: Psram,sdram,sram,ddram

KEIL MDK View Code amount, RAM usage--ro-data, Rw-data, zi-data explanation (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.