Hi, How can i compute the ROM, RAM size and runtime consumed by a function in C. For example: void main() { ... f(); } f() { ... ... } How can i compute the RAM, ROM and runtime consumed by the function f() from the listing file and the map file? Please help me. Thanks
"masters thesis ... to optimize the interfaces ... of embedded systems in order to reduce the development cost." (my emphasis) Maybe I'm just being thick here, but how are you going to determine the effect on development costs? The measurements you describe seem to concentrate solely on the generated code size? Are you also considering the tradeoff of code size against execution speed? "I provide a table at the end of my thesis and the developer can look into the table and say for a fuction call with one argument this much amount of ROM, RAM and runtime is consumed." I think you may be taking rather a simplistic view here, I'm afraid. Optimisations like Common-Tail merging, Re-Use of Common Entry Code, Common-Block Subroutines, Linker Code Packing will make this extremely difficult - if not impossible - to determine! :-( For the 8051 in particular, the number of arguments is only one factor: * the types of the arguments can be far more significant; * The Memory Model used makes a big difference; * etc, etc, etc,... And, of course, the efficiency of the code inside the function can have far more impact than just the call-return overhead!
You might be interested in running the Keil tools at different optimization levels and studying the generated code. I think you'll find that the notion of "a function call" or "a line of code" is a bit hard to pin down. The "common entry" optimization, for example, finds bits and pieces of common function call sequences and turns them into subroutines, so two different function calls share the same setup code. (Sometimes I get the impression that any four bytes in a row that match get replaced by an ACALL/RET to save space.) You might also want to consider the difference between passing registers in parameters and on the stack. The 8051 tools are a bit unusual in the way they handle the stack -- it's to be avoided, because the architecture doesn't cope with it well. Spilling parameters into memory has substantial space, speed, and reentrancy costs, and so there's a strong emphasis on keeping parameters in registers. A "function call with one parameter" with have vastly different costs if it is reentrant or not. Functions with multiple parameters are going to have varying results depending on the exact size and order of the parameters.