 | Discussion Forum |  |
|
|
Global Variable InitializationNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Robert Sagusti Posted 12-Dec-2001 19:52 GMT Toolset C51 |  Global Variable Initialization Robert Sagusti Hello,
I have variables initialized at the global level in my .c file but they are never being initialized. When I watch in d-scope and INIT.a51 is executing:
?C_START: MOV DPTR,#?C_INITSEG LOOP: WATCHDOG CLR A MOV R6,#1 MOVC A,@A+DPTR JZ INITEND <------Here!!!!!!!!!! INC DPTR MOV R7,A ANL A,#3FH JNB ACC.5,NOBIG
the code jumps right to INITEND because the MOVC instruction puts zero into the accumulator, even though I've initalized global variables with values. Anyone see the problem?
Thanks,
Bob
| | Read-Only Author Jon Young Posted 12-Dec-2001 21:02 GMT Toolset C51 |  RE: Global Variable Initialization Jon Young Is it possible that all your files are from assembly sources (or C translated to assembly sources)? In which case just add a dummy C file to your project. | | Read-Only Author Robert Sagusti Posted 12-Dec-2001 21:18 GMT Toolset C51 |  RE: Global Variable Initialization Robert Sagusti Thanks Jon,
The myFile.obj is object from myFile.c
Basically the issue is if I list INIT.obj before STARTUP.obj in the linker list, the startup code does not get jumped to.
If STARTUP.obj is linked before INIT.obj, everything runs fine. | | Read-Only Author Jon Ward Posted 12-Dec-2001 23:04 GMT Toolset C51 |  RE: Global Variable Initialization Jon Ward Yep,
This is documented in the following knowledgebase article:
http://www.keil.com/support/docs/787.htm
Jon
| | Read-Only Author Robert Sagusti Posted 13-Dec-2001 13:47 GMT Toolset C51 |  RE: Global Variable Initialization Robert Sagusti Jon,
Thanks for the diligence in helping me, I appreciate it. Honestly, I looked through the knowledgebase and didn't find this. I don't know how I missed it. I'll try the proposed solution and hopefully, it works.
Thanks again,
Bob | | Read-Only Author Bahri Okuroglu Posted 21-Dec-2001 15:47 GMT Toolset C51 |  RE: Global Variable Initialization Bahri Okuroglu What about the STARTUP.A51 module. Should it also be placed at the end of the linker parameters? | | Read-Only Author Robert Sagusti Posted 21-Dec-2001 16:32 GMT Toolset C51 |  RE: Global Variable Initialization Robert Sagusti I ran into a problem where I had my c relocatable as the first parameter , and startup.obj as the second. When it was in this configuration, the reset vector was not listed as the first instruction in the .hex file. Putting startup .obj as the first parameter corrected this.
Just my experience, hope it helps. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|