What are RO, RW and ZI generated by Keil compilation?

Publisher:平静宁静Latest update time:2019-04-18 Source: eefocusKeywords:Keil Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

To understand RO, RW and ZI you need to first understand the following:

1. Composition of ARM program:
        The "ARM program" mentioned here refers to the program being executed in the ARM system, not the bin image file saved in ROM. Please pay attention to the difference.
         An ARM program consists of 3 parts: RO, RW and ZI. RO is the instruction and constant in the program; RW is the initialized variable in the program; ZI is the uninitialized variable in the program.
         From the above 3 points, it can be understood that RO is readonly, RW is read/write, and ZI is zero
 
          . 2. Composition of ARM image file
         The so-called ARM image file refers to the bin file burned into ROM, also called image file. It is called Image file below.

         Image files contain RO and RW data. The reason why image files do not contain ZI data is that ZI data is all 0, so there is no need to include it. Just clear the area where ZI data is located before running the program. Including it will waste storage space.


            Q: Why must RO and RW be included in the Image?
            A: Because the instructions and constants in RO and the variables initialized in RW cannot be created out of nothing like ZI.
 
         3. The execution process of the ARM program
         From the above two points, we can know that the image file burned into the ROM is not exactly the same as the ARM program in actual operation. Therefore, it is necessary to understand how the ARM program reaches the actual running state from the image in the ROM. In fact
            , the instructions in RO should at least have the following functions:
            1. Move RW from ROM to RAM, because RW is a variable and variables cannot exist in ROM.
            2. Clear all RAM areas where ZI is located, because the ZI area is not in the 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. Similarly: variables cannot exist in ROM. In the
            initial stage of program operation, the C program can access variables normally only after the instructions in RO complete these two tasks. Otherwise, only code without variables can be run.


            After all the above, you may still be confused. What are RO, RW and ZI? Below I will give a few examples to explain what RO, RW and ZI mean in C.
1. RO
            Look at the following two programs. There is a statement between them, which is to declare a character constant. Therefore, according to what we said before, there should only be one byte difference in RO data (character constant is 1 byte).
            Prog1:
            #include
            void main(void)
            {
            ;

            }


            Prog2:
            #include
            const char a = 5;
            void main(void)
            {
            ;
            }
            The compiled information of Prog1 is as follows:
            =====================================================

            Code RO Data RW Data ZI Data Debug
            948 60 0 96 0 Grand Totals

            =====================================================
            Total RO Size(Code + 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)
            =======================================================
            The information compiled by Prog2 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)
            ===================================================
            From the information after the above two programs are compiled, we can see that:
            The RO of Prog1 and Prog2 contains two types of data: Code and RO Data. The only difference between them is that the RO Data of Prog2 has one more byte than that of Prog1. This is consistent with the previous speculation.
            If an instruction is added instead of a constant, the result should be a difference in the size of the Code data.


2. RW
            Again, look at the two programs again. The only difference between them is an "initialized variable". According to what has been said before, the initialized variable should be counted in RW, so the size of RW should be different between the two programs.
            Prog3:
            #include
            void main(void)
            {
            ;
            }
            Prog4:
            #include
            char a = 5;
            void main(void)
            {
            ;
            }
            The information after Prog3 is compiled is as follows:
            ======================================================
            Code RO Data RW Data ZI Data Debug
            948 60 0 96 0 Grand Totals
            =========================================================
            Total RO Size(Code + 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)
            ======================================================
            The information compiled by Prog4 is as follows: 
   ======================================================
            Code RO Data RW Data ZI Data Debug
            948 60 1 96 0 Grand Totals
            =========================================================
            Total RO Size(Code + 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 there is only one byte difference between Prog3 and Prog4 in RW Data, which is caused by an initialized character variable "a".
 
3. ZI
            Looking at the two programs again, the difference between them is an uninitialized variable "a". From the previous understanding, it can be inferred that the only difference between the two programs should be the size of ZI.
            Prog3:
            #include
            void main(void)
            {
            ;
            }
            Prog4:
            #include
            char a;
            void main(void)
            {
            ;
            }
            The information after Prog3 is compiled is as follows:
            ========================================================
            Code RO Data RW Data ZI Data Debug
            948 60 0 96 0 Grand Totals
            ============================================================
            Total RO Size(Code + 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)
            ==========================================================
            The information compiled by Prog4 is as follows:
            ========================================================
            Code RO Data RW Data ZI Data Debug
            948 60 0 97 0 Grand Totals
            ============================================================
            Total RO Size(Code + 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             )
            === ...             Appendix:             Program compilation command (assuming the C program is 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             The compiled information of tst.o is in the aa.map file.             ROM mainly refers to: NAND Flash, Nor Flash             RAM mainly refers to: PSRAM, SDRAM, SRAM, DDRAM














Keywords:Keil Reference address:What are RO, RW and ZI generated by Keil compilation?

Previous article:A red cross appears in MDK, but the program compiles normally without errors
Next article:Description of the FLASH size occupied by the bin file generated after MDK compilation

Recommended ReadingLatest update time:2024-11-16 15:56

A Simple Study on the Delay Program of Keil C 51 Single Chip Microcomputer
    When using a single-chip microcomputer, we often encounter situations where a short delay is required. The required delay time is very short, usually tens to hundreds of microseconds (us). Sometimes very high precision is also required, such as when using a single-chip microcomputer to drive a DS18B20, the error to
[Microcontroller]
STM32 disassembly code analysis on KEIL platform
  The assembly code of different platforms is different. The earliest assembly code was invented in the 1950s, which is older than many people's parents. It is outdated and there is no need to learn how to write assembly code. It is enough for a company to have one person who knows how to write assembly code. But lear
[Microcontroller]
Design of LED display control system based on Proteus and Keil μVision 3
The design of LED display control system adopts AT89C51 microcontroller as the main controller, adopts two modes of LED row and column display and keyboard synchronous interrupt request display, realizes serial communication and performs switching control between the two modes. The system successfully realizes the cont
[Microcontroller]
Design of LED display control system based on Proteus and Keil μVision 3
KEIL C51 printf formatted output special usage
/******************************************* KEIL has expanded the b, h, and l to set the input byte width: (1) b is 8 bits (2) h is 16 bits (default) (3) l is 32 bits In Keil C51, when using printf to output a single-byte variable, you need to use %bd, such as unsigned char counter; printf("Current count: %bd\n", cou
[Microcontroller]
STM32 code debugging on RAM in Keil MDK environment
I haven't touched Keil since 51. I started using Keil MDK again yesterday afternoon, but this time it's for ARM. The STM32W108 debugging in the past few days was all done on IAR. I just debugged a routine on STM32F103ZE-EK, and found that there is a way to configure code debugging in RAM. I knew there was an iar-cfg.i
[Microcontroller]
Detailed explanation of Keil C51 software usage
Section 1 Keil C51 Compiler Control Instructions  The control instructions of the C51 compiler are divided into three categories: source file control, target file control and list control.  1. Source file control  NOEXTEND: C51 source files are not allowed to use ANSI C extension functions.  DEFINE (DF): define prepro
[Microcontroller]
Use Keil to write the program and download it to the microcontroller
When programming microcontrollers, keil uvision2 is often used to write programs. Let's take the AT89C51 microcontroller as an example to learn how to use keil uvision2 to write programs. The general steps for writing programs with keil uvision2 are as follows: 1. Create a new project 2. Create a new source progra
[Microcontroller]
Keil function inline
       Inline function means: when the compiler finds that a certain code is calling an inline function, it does not call the function, but inserts the entire code of the function into the current position. The advantage of this is that it saves the calling process and speeds up the program, but because the inline fun
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号