I have developed a small Single Board computer, with a few customizations..
I am well versed in Assembly programming for 8052, but not for C. I have written driver functions for the devices on the board in assembly and this "BIOS" will be burned in the on-chip 20KB (89c55) eeprom as a simple monitor program. Upon startup, it will initialize some variables, a custom protocol stack and then jump to user program rom (at 8000h) address.
I want to write user codes in C, but in SMALL and / or COMPACT modes, since C uses the internal data ram for stack and other variables, this might clash with the BIOS variables that are at fixed internal-ram addresses.
Secondly, the BIOS program will initialize stack to reside in the extra 128-bytes ram (80h and above) while it is not certain where C will put the stack to start at.
Can anyone guide me as to how this situation can be avoided ?
"a custom protocol stack ... I want to write user codes in C"
When this stack is called from the C user code, the stack subroutine should follow the C calling convention. You have to read carefully the sections of C manual starting from this page, to know how to configure your asm code to fit to C convention.
Interfacing C to Assembler http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm
Also this kb will help you.
C51: CALLING ASSEMBLY ROUTINES FROM C http://www.keil.com/support/docs/50.htm "since C uses the internal data ram for stack and other variables, this might clash with the BIOS variables that are at fixed internal-ram addresses."
Apply DATA and IDATA linker directive to the C user code, so that the C working domain doesn't overlap your "BIOS" variables on the absolute address.
DATA Linker Directive http://www.keil.com/support/man/docs/bl51/bl51_data.htm IDATA Linker Directive http://www.keil.com/support/man/docs/bl51/bl51_idata.htm
Tsuneo