The .map file generated after compiling the code in the Keil C51 contains a lot of useful information, and when I recently looked at the .map file to check the space usage of each part of the code, I saw some strange symbols in the .map file
The compiler actually links these seemingly "library" files when compiling the code, so who called these files? Why does the compiler call these libraries? To answer these questions, we need to take a closer look at the information provided by these .map files.
Looking at the .map file from the bottom to up, we will find that a series of variables have this VALUE on the left, and it seems that this value is very regular and seems to be stored in one space, then we might as well guess that this is the address of the compiler's compiled modules and instructions. All that is needed now is to find a way to confirm this point:
Click DEBUG-> to find the corresponding address in the disassembly window, and use the following library as an example to find it:
Look for the address 0x07B
Surely, we found the call of this library on the address of 0x07B, indicating that the value in the .map file is indeed the corresponding address, and to know where the library is called, you need to follow up further:
1、First, we need to open the Call Stack window
2、Set a breakpoint on the address you just found
3、run! Let the program run until it stops running at the breakpoint before looking at the Call Stack window
This is the case of the stack after stopping at the breakpoint position in the example code, from this diagram we can know that the cal_bat_cap(), battery_handle_100ms, ui_handle_100ms these 3 functions were executed before calling this library, and found that the cal_bat_cap() function has a "+" sign here, let's click it to see:
It seems that in these functions, there are variable operations in this function, plus C? UIDIV is a division library, the answer is already coming out, let's follow the vine and find this function to see
You can see that there is indeed a division operation in it, and an unsigned type of variable is used, so this C? UIDIV is an unsigned division library. At this point, we have found where this library is called in the code.
When we know where to use these libraries in the code, we can reduce the calls of these libraries by modifying the code, such as the unsigned division library and the signed division library are two libraries, whether we can save one; Is it possible to remove pointer operations to save pointer call libraries....to the point of optimizing the code space.
Original article, Please mark the attribution when reprinting. SINHMICRO,www.sinhmicro.com。