Hey guys I see there are numerous threads and support docs with mixing C + ASM. but I am still pulling hair out. I can get C to use a register I declared in asm eg:
CODLO DATA 39D
by using
extern unsigned char CODLO; in c
but I found that the address isn't reserved and that the memory location 39D is actually used by another variable delcared in c later in the program. So I am trying to get asm to use a variable I have declared in C...
so, I declare
unsigned char CODLO;
in C and in ASM i put
EXTERN DATA CODLO.
I get the compilation error:
smartcode.a51(2): error A48: DATA-ADDRESS EXPECTED
hope someone can help :)
Xarion
Hey guys I see there are numerous threads and support docs with mixing C + ASM. but I am still pulling hair out.
What you're looking for is in the C51 compiler manual. No need to look for any other docs.
http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm
Hi Christoph,
thanx for the reply, if i assign a register a name in ASM does the compiler know not to use that memory location for other c variables? should i declare all my registers i use in my asm file as public ?
if i assign a register a name in ASM does the compiler know not to use that memory location for other c variables?
No, it won't. The aspects of mixing C and assembly routines are described, in great detail (far greater than anything that could be described in a posting here), in the compilers manual. This includes things like calling conventions and register usage.
http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm
My ASM and c still seem to be fighting with one another, another variable I have declared in C is being overwritten by the ASM code. I have followed the docs you posted to me (http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm)
it says .... To access these variables in assembler, you must create an extern declaration that matches the original declaration. For example:
EXTERN DATA(jim)
if I do that it does not compile and i get the errors in my original post..
so what I have done now, I have declared the register in ASM :
CODHI DATA 41D CH_REG DATA 40D CODLO DATA 39D
and then at the top i put
PUBLIC CODHI PUBLIC CODLO PUBLIC CH_REG
and in the c i put:
extern unsigned char CODHI ; extern unsigned char CH_REG; extern unsigned char CODLO ;
this gives me the problem with the variables being overwritten. I have no idea where to turn from here :(
thanx again