How to tell SDCC the location of code memory

Discussion in 'Embedded Systems and Microcontrollers' started by ASHOK DAS, Apr 25, 2015.

  1. ASHOK DAS

    Thread Starter New Member

    Apr 25, 2015
    4
    0
    Hi all,

    This problem may be very simple for c programmers but for a assembly guy like me its very critical. I have a 89S51 board, which have a external static RAM located at 0x2000. I use this for both code and data memory. While assembling any program, I use ORG directive to tell assembler to start the code from 0x2000. This works fine. Now I moved to C (SDCC as no way I can afford KEIL). Now how to tell SDCC to compile the code from address 0x2000 ? I could not find any straight answer. SDCC manual has two command line options:

    --code-loc <Value> The start location of the code segment, default value 0. Note when this option is used the interrupt vector table is also relocated to the given address. The value entered can be in Hexadecimal
    or Decimal format, e.g.: --code-loc 0x8000 or --code-loc 32768.


    and

    --xram-loc <Value> The start location of the external ram, default value is 0. The value entered can be in Hexadecimal or Decimal format, e.g.: --xram-loc 0x8000 or --xram-loc 32768.

    I used these like

    sdcc --code-loc 0x2000 --xram-loc 0x2000 serial_101.c

    The program serial_101.c compiles successfully, but starting location is 0x0000 as i observed in generated ASM file. I am using Windows7 64 and WindowsXP 32. How this can be achived ? Need your expert advice.

    Thanks
    Ashok
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,180
    1,800
    Just as an experiment try making them different. Since the 8051 has separate control signals for code memory and data memory the compiler writers might not have anticipated that anybody would want to colocate code memory and data memory. Other processors allow this so it is actually a surprise to me.
     
  3. ASHOK DAS

    Thread Starter New Member

    Apr 25, 2015
    4
    0
    Okay, but my primary objective is to place code in 0x2000. I am forgetting the data part now. As 8051 has 64k code memory address space. Anybody may want to use a space beyond internal 4k space to place the code as I am trying to do. How c compilers will handle this? Assemblers simply use ORG directive to place code anywhere from 0 to 64 k.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,180
    1,800
    Placing segments in memory is not part of the compilers job. This job is done by the linkage editor or linker. Normally you compile modules into object files and then you link them with libraries to form an executable file. What I was trying to get at was to see if you could place the code at some location other than zero. Problem is I don't think 8051 has a mechanism to relocate the interrupt vectors. The AVR does, but that is not useful to you.
     
  5. ASHOK DAS

    Thread Starter New Member

    Apr 25, 2015
    4
    0
    So you are saying that I should compile as usual an then use my 8051 trainer to place the code at external code memory and see what happens? Surely i will do. Actually the problem is that in the trainer the internal flash memory is used by the bootloader. So internal code memory is inaccessible. I have to use external code memory for any development. The address starts from 0x2000. Till now i used assembly to write programs. If I cannot use C for development of code in trainer then the trainer is of no use ? I cannot learn embedded c in trainer then?
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,180
    1,800
    You are jumping to conclusions not supported by the evidence. The SDCC is a system that many people use. I'm suggesting that you don't necessarily know it well enough to draw any conclusions about what it will or won't do. I am suggesting that you experiment carefully by changing one thing at a time so you can see what it is trying to do. All we think we know at the present is that you don't seem to be able to set code memory and external data memory to the same location.
     
    absf likes this.
  7. ASHOK DAS

    Thread Starter New Member

    Apr 25, 2015
    4
    0
    Ok i will, thanks for the suggestions.
     
Loading...