where variables without 'volatile' al...

2011-05-04
2013-03-12
  • bruce_jiang
    bruce_jiang
    2011-05-04

    As I discovered, for internal-ram mode, there are 128 bytes limitation for declaring volatile variables in the interrupt service program. And I think SDCC would allocate these volatile variables to the high 128 bytes of the internal ram. Is it right?
    But for a sub-program (which is used in the interrupt service program), I declared 256 bytes variables without volatile, it can work. So where does SDCC allocate these sub-program's variables?

     
  • Maarten Brock
    Maarten Brock
    2011-05-04

    This has nothing to do with volatile or interrupts. In the default small memory model all variables are located in internal RAM between 0x08 and 0x7F. If register banks >0 are used or bit variables you have even less. SDCC will never place variables in the upper 128 bytes of internal ram unless you specifically put them there with __idata. To use 256 bytes for variables you must put them in external ram with either __pdata or __xdata or use the medium or large memory model.

     
  • bruce_jiang
    bruce_jiang
    2011-05-05

    OK. Thanks. I see the memory allocation in the file: *.map and *.mem.

     
  • bruce_jiang
    bruce_jiang
    2011-05-05

    But what makes me confused is:
    In general function, if I declare 64 of DWORD variables, without volatile, how does SDCC allocate them? ( sdcc can compile it with no error)
    Although from the sdcc userguide, it says local variables would be allocated to internal ram. But 64x4=256 bytes has exceed the internal ram (small memory mode). So where are the local variables?

     
  • Maarten Brock
    Maarten Brock
    2011-05-05

    SDCC does not check allocation in the compile stage but only in the linking stage (for mcs51). Which memory model are you using? I assume you use mcs51. Please report all command line options you used. Do you see these variables in the .map file? In which segment? Does it overflow?

     
  • bruce_jiang
    bruce_jiang
    2011-05-06

    small memory mode.  mcs51.  I can't see the variables in the .map file.
    There are no #pragma in the source file. So from the sdcc userguide, the local variables would not be allocated to stack.
    The command is:
    sdcc -iram-size 256 -int-long-reent rom.c

     
  • Maarten Brock
    Maarten Brock
    2011-05-07

    test.c

    long array[64];
    void main()
    {
    }
    

    If I compile this with:
    sdcc test.c

    I get:

    ?ASlink-Error-Could not get 256 consecutive bytes in internal RAM for area DSEG.

     
  • bruce_jiang
    bruce_jiang
    2011-05-09

    Yes. If I declare the variables like you said, SDCC would report an error.
    But my declaration is as follows:
    void test( ) {
    long dw_r00=0x00;
    long dw_r01=0x01;
    long dw_r02=0x02;

    long dw_r3f=0x3f;    // totally 64 long.
    }

    void main()
    {   test( );
    }
    Then SDCC would not report an error, and compile ok.  It seems SDCC allocate the variables in the OSEG.

     
  • Maarten Brock
    Maarten Brock
    2011-05-09

    Well, if you make them unused local variables they get optimised out.

    If they were not optimised out you'd get:

    ?ASlink-Error-Could not get 256 consecutive bytes in internal RAM for area OSEG.

     
  • bruce_jiang
    bruce_jiang
    2011-05-09

    OK. Thanks.