This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c-variable definitions in assembly main

Hi,

I am programming on the Cypress FX2 (8051 compatible) and I have a problem that my variables declared in a c-function do not get initializes properly.

My main program is written in assembly, since I need to have an ISR, which is very short and i want to have full control over what the proc. does during that ISR. I have to include a c-file in my project, which initializes a bunch of registers for a special interface on my USB chip. The problem is that the linker does not include that data segment.

my data is defined this way:

const char xdata WaveData[128] = {128 bytes}

do i need to write an initialization function in C, which moves all that data or is there a way for force the inclusion of that data segment?

thanks,

Greg

ps.: sorry if i am not clear.

Parents
  • In general, C run-time code is responsible for initializing initialized data before main() starts. There is no way for a linker to link a segment of pre-defined values "into RAM". The RAM will power up in an undefined state. The initial values will have to exist somewhere in your ROM, and be copied to RAM to initialize the data segment upon startup. (Similarly, uninitialized variables must be zeroed to conform to the ANSI spec.)

    In your case, however, you don't have a main(), and you probably aren't initializing the C run-time environment.

    Take a look at the lib\init.a51 code, which you would normally add to your C projects that use initialized data. You'll need to execute this or similar code in your own startup procedure before you call the C functions.

Reply
  • In general, C run-time code is responsible for initializing initialized data before main() starts. There is no way for a linker to link a segment of pre-defined values "into RAM". The RAM will power up in an undefined state. The initial values will have to exist somewhere in your ROM, and be copied to RAM to initialize the data segment upon startup. (Similarly, uninitialized variables must be zeroed to conform to the ANSI spec.)

    In your case, however, you don't have a main(), and you probably aren't initializing the C run-time environment.

    Take a look at the lib\init.a51 code, which you would normally add to your C projects that use initialized data. You'll need to execute this or similar code in your own startup procedure before you call the C functions.

Children