View previous topic :: View next topic |
Author |
Message |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
Ram allocation problem? |
Posted: Sun Jan 23, 2011 10:22 am |
|
|
Small test program to explain and run. "Ram allocation problem?
Don't run it in hardware!
When calling fu2() in function fu1(), this call use 11 byte ram why?
In the list file it is just a simple function call?
The function is called one time before therefore the code is inserted in the hex file one time!
Is there a error in the way the compiler calculate the ram used???
Ex.
Code: | #include "18F14K50.h" //you can use any chip here...
#device PASS_STRINGS=IN_RAM
#use delay(clock=8M,int)
#use rs232(baud=9600)
void Prn(char *str1){
printf(str1);
}
void fu2(){
Prn("1234567890");
}
int1 fu1(){
Prn("1234567890");
fu2(); //Try to remove this function and look in the lst file, there are 11 byte ram in dif! But the list file just indicate a simple function call?
}
void Test1(){
fu1();
fu2();
}
void main(){
Test1();
}
|
Compiler in 4.114 but tested in 4.116 & 4.93 with same behavior
With call to fu2() -> Ram used 33 byte
ROM used: 278 bytes (2%)
Largest free fragment is 16106
RAM used: 4 (1%) at main() level
33 (4%) worst case
Stack: 6 locations
without call to fu2() ->Ram used 22 byte
ROM used: 278 bytes (2%)
Largest free fragment is 16106
RAM used: 4 (1%) at main() level
22 (3%) worst case
Stack: 5 locations |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 23, 2011 1:33 pm |
|
|
Not to sure but since you've allowed 'passing strings = in RAM', maybe the compiler has to make room for that to happen?
hmmm...11 bytes equals your original strings length...
Does the RAM used vary exactly with your string (change to 1234 to see ?)??
I'd have to see the dorlst to figure it out, but have to go shovel some more snow in -20C weather... |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sun Jan 23, 2011 2:54 pm |
|
|
The ram is equal to the "const" length. But this is _not_ the real problem if you insert the function call in another function there _not_ call the "Prn(...) function there are not ram problem.
I find this real strange, because the "list" file look ok to me.
To test just copy & paste my ex. it will compile nicely. |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Mon Jan 24, 2011 1:18 pm |
|
|
If any one can explain it, it will be nice. I don't understand it? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 24, 2011 1:29 pm |
|
|
Look at the .SYM file. It shows that the compiler is allocating an 11-byte
RAM buffer to functions fu1 and fu2. This is so it can load the constant
strings into ram to pass them to the Prn() function.
Quote: | 000 @SCRATCH
001 @SCRATCH
001 _RETURN_
002 @SCRATCH
003 @SCRATCH
005-00F fu1.@STRPARAM
010-01A fu2.@STRPARAM
010 fu1.@SCRATCH1
011 fu1.@SCRATCH2
012 fu1.@SCRATCH3
013 fu1.@SCRATCH4
01B fu2.@SCRATCH1
01C fu2.@SCRATCH2
01D-01E Prn.str1
01D fu2.@SCRATCH3
01E fu2.@SCRATCH4
01F @PSTRINGR_70.@SCRATCH1
020 @PSTRINGR_70.@SCRATCH2
021 @PUTCHAR_1_.P1
F6B.6 C2OUT
F6D.6 C1OUT |
|
|
|
|