Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

what is the additonal asm code generated by keil for?

Status
Not open for further replies.

Jasper Chow

Junior Member level 3
Junior Member level 3
Joined
Nov 14, 2013
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
218
I wrote a simple 8051 C program in keil, debugged it and found the linker created lots of additional asm code that seems pointless. The first instruction of the program is a LJMP to a far distant place ,and the program starts excuting the additional asm code, most of which is useless actions like
data transferring between the accumulator and general registers. The program goes through hundreds of machine cycles before it reaches the entry of main function. I am confused. What are those extra instructions for?
 

Before main is executed the following must be done:

1. Setting a stack pointer
2. Setting all initialized variables, normally done by copying blocks of data
3. Clearing all other variables.

For step 2 some compilers go through a linked list to find all blocks that should be copied and their destination addresses.

The asm code for this is static and common for all programs, regardless of any initialized variables.
 

Setting a stack pointer

This task is especially important when working with the Watch Dog feature enabled.
Once a restart is done, it prevents the occurrence of errors hard to be debugged.
 

Before main is executed the following must be done:

1. Setting a stack pointer
2. Setting all initialized variables, normally done by copying blocks of data
3. Clearing all other variables.

For step 2 some compilers go through a linked list to find all blocks that should be copied and their destination addresses.

The asm code for this is static and common for all programs, regardless of any initialized variables.

I see what the asm code does for setting a stack pionter, but it only costs a few instructions. For the step2, the variables' value is already stored in ROM, the program generally inititializes the variables at the point where the variables are first used.
What bewilders me most is the complier looks like creating bunches of code that wastes machine cycles, some loops do nothing but reducing a value to zero, some data tranfers and logic computations only create invalid values for the accumulator and registers.
 

If you own a full Keil license you should be able to review all run time library sources, icluding the startup code you are talking about. There's no need to guess about it.

As far as I experienced so far, Keil C51 startup code doesn't implement "pointless" activity. It's more likely that it's doing things that are required to support the C code you have written. A certain extent of startup code may have been configured by general compiler options you selected, if it's actually required for your application you should be able to deselect it.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top