0

I ve written a code in C for ATmega128 and

I d like to know how the changes that I do in the code influence the Program Memory.

To be more specific, let's consider that the code is similar to that one:

   d=fun1(a,b);
   c=fun2(c,d);

the change that I do in the code is that I call the same functions more times e.g.:

   d=fun1(a,b);
   c=fun2(c,d);
   h=fun1(k,l);
   n=fun2(p,m);
   etc...

I build the solution at the AtmelStudio 6.1 and I see the changes in the Program Memory.

Is there anyway to foresee, without builiding the solution, how the chages in the code will affect the program memory?

Thanks!!

Herc11
  • 49
  • 1
  • 3
  • Are you asking to forecast how much space in program memory your program will occupy? This is usually difficult and depends on the (optimisation) settings of your compiler. – andrsmllr Jun 27 '13 at 10:54
  • Yes damage. That is exactly what I am asking. Thanks – Herc11 Jun 27 '13 at 11:23

1 Answers1

0

Generally speaking this is next to impossible using C/C++ (that means the effort does not pay off).

In your simple case (the number of calls increase), you can determine the number of instructions for each call, and multiply by the number. This will only be correct, if the compiler does not inline in all cases, and does not apply optimzations at a higher level.

These calculations might be wrong, if you upgrade to a newer gcc version.

So normally you only get exact numbers when you compare two builds (same compiler version, same optimisations). avr-size and avr-nm gives you all information, for example to compare functions by size. You can automate this task (by converting the output into .csv files), and use a spreadsheet or diff to look for changes.

This method normally only pays off, if you have to squeeze a program into a smaller device (from 4k flash into 2k for example - you already have 128k flash, that's quite a lot).

This process is frustrating, because if you apply the same design pattern in C with small differences, it can lead to different sizes: So from C/C++, you cannot really predict what's going to happen.

Beryllium
  • 12,808
  • 10
  • 56
  • 86