Hello Maarten,

I would never have thought of that approach, so thanks. 

I rewrote my sample, to define the global variables in separate header files, 
and it still left the gap.  Then I added separate >source< files with the 
corresponding headers, and the gap was filled in.

Sample code:

// three header files are empty, no text at all, but must exist
// three source files with the global variable definitions
// source file, ram_test1.c
char  oneChar1[16];
// source file, ram_test2.c
__bit oneBit = 0;
// source file, ram_test3.c
char  oneChar2[16];

// main file, ram_test.c
#include <8052.h>

#include "ram_test1.h"
#include "ram_test2.h"
#include "ram_test3.h"

void delay(int jj, int kk)
{
    int j;
    int k;
    for(k=0; k < kk; k++) {
        for(j=0; j < jj; j++) {
        }
    }
}

void main(void)
{

    while(1) {
        delay(100,200);
    }
}
// end of sample code

Internal RAM layout:
      0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
0x10:|a|a|a|a|a|a|a|a|Q|Q| | | | | | |
0x20:|B|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
0x30:|b|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|

Very nice!  

Thanks again,  Rich.

--- On Fri, 10/26/12, Maarten Brock <sourceforge.br...@dse.nl> wrote:

> From: Maarten Brock <sourceforge.br...@dse.nl>
> Subject: Re: [Sdcc-user] data ram layout, unused gap before a bit variable
> To: sdcc-user@lists.sourceforge.net
> Date: Friday, October 26, 2012, 3:37 PM
> Hi Rich,
> 
> The variables from each source file are placed either in the
> overlay or
> data segment. But they are only subdivided by file, not by
> function or
> even variable. And arrays or structs of course cannot be
> subdivided at
> all. So the whole block of all variables from one source
> file is placed in
> one block of memory. And if it doesn't fit before the bit
> area it has the
> come after. But the block from the next source file (or the
> overlay block)
> can fill the gap. If you have many source files with few
> variables, you'll
> find everything filled up. OTOH if you put all variables in
> one file it's
> unlikely to come before the bits. And the bits can only use
> the area from
> 0x20-0x2F. When there are no bits used then the memory space
> is not split.
> 
> Maarten
> 
> > Hello Sdcc users,
> >
> > I've been using sdcc for a year or two, thanks to all
> the developers for
> > the sdcc project.
> >
> > I'm writing to ask for help understanding how to manage
> ram usage with the
> > mcu8051.  I've read over the sdcc manual several
> times and have searched
> > through the mailing list history.  I'm hoping that
> someone can point me in
> > the right direction.
> >
> > The issue is that with a __bit variable defined, and
> several dozen __data
> > variables defined, there is a large gap of unused ram
> between the register
> > bank and the bit variable.
> >
> > I'm sure I could force usage of the unused ram
> locations by using absolute
> > '__at' addresses, but perhaps there's a way for sdcc to
> manage the ram
> > layout automatically.
> >
> > Here is some sample code.  This sample includes a
> function to demonstrate
> > overlay variables, which is shown in the memory
> map.  Take out the
> > function and you'll get the same results.  I
> included the function to show
> > that overlay variables work nicely.
> >
> > // start of code sample
> > // SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390
> > // /pic16/pic14/TININative/ds400/hc08/s08
> > // 3.2.0 #8008 (Jul  6 2012) (MINGW32)
> > #include <8052.h>
> >
> > char  oneChar1[24];
> > char  oneChar2;
> >
> > __bit oneBit = 0;
> >
> > void delay(int jj, int kk)
> > {
> >     int j;
> >     int k;
> >     for(k=0; k < kk; k++) {
> >         for(j=0; j <
> jj; j++) {
> >         }
> >     }
> > }
> >
> > void main(void)
> > {
> >
> >     while(1) {
> >         delay(100,200);
> >     }
> > }
> > // end of code sample
> >
> > Here is a portion of the memory map, showing the large
> gap of unused data
> > ram:
> >
> > Internal RAM layout:
> >       0 1 2 3 4 5 6 7 8 9 A B
> C D E F
> > 0x00:|0|0|0|0|0|0|0|0|Q|Q| | | | | | |
> > 0x10:| | | | | | | | | | | | | | | | |
> > 0x20:|B|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
> > 0x30:|a|a|a|a|a|a|a|a|a|a|S|S|S|S|S|S|
> >
> > Comment out the __bit variable and this is the memory
> map that results.
> > You can see the __data variables start right after
> register bank 0,
> > followed by the QQ overlay variables.
> >
> > Internal RAM layout:
> >       0 1 2 3 4 5 6 7 8 9 A B
> C D E F
> > 0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
> > 0x10:|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
> > 0x20:|a|Q|Q|S|S|S|S|S|S|S|S|S|S|S|S|S|
> > 0x30:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
> >
> > Restore the __ bit variable and comment out the 'char
> oneChar2' variable
> > and you get this memory map, showing the __bit variable
> between the __data
> > variables and the overlay variables.
> >
> > Internal RAM layout:
> >       0 1 2 3 4 5 6 7 8 9 A B
> C D E F
> > 0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
> > 0x10:|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
> > 0x20:|B|Q|Q|S|S|S|S|S|S|S|S|S|S|S|S|S|
> > 0x30:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
> >
> > Hope all this makes sense.
> >
> > Thanks for your time,
> > Rich.
> 
> 
> ------------------------------------------------------------------------------
> WINDOWS 8 is here. 
> Millions of people.  Your app in 30 days.
> Visit The Windows 8 Center at Sourceforge for all your go to
> resources.
> http://windows8center.sourceforge.net/
> join-generation-app-and-make-money-coding-fast/
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
> 

------------------------------------------------------------------------------
WINDOWS 8 is here. 
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to