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

Local varible in same address

Hi All

I write a function like this

test.c
void a(U8 val)
{ U8 ch=0;

dev[ch].fun1(val); <--this is a function pointer , it will call the b function

dev[ch].fun2(val); <--Fail here
}

void b( U8 val)
{ U8 dummy = val *5;

writeReg[0x55AA]= dummy;
}

after run the " dev[ch].fun1(val)"

The ch varible will be change , so it will fail when run " dev[ch].fun2(val)"

I found the varible is in the same memory address, How can I avoid it??

and how can I know the memory map of all local varible ??

I found the m51 file , the data is map to 18h to 28h

DATA 0018H 0028H UNIT ?DT?TEST

why ch varible is map to 0x40 and same as dummy varible??

Thanks for you kindly help and sorry for my poor english

Parents
  • "I found the 'ch' varible is in the same memory adddress as 'dummy' varible"

    This is perfectly normal & correct operation for the Keil C51 compiler.

    This is called Overlaying - it is Keil's solution to the problem that the 8051 has virtually no stack to speak of.

    Overlaying achieves at build-time what "normal" compilers achieve at run-time by using the stack.

Reply
  • "I found the 'ch' varible is in the same memory adddress as 'dummy' varible"

    This is perfectly normal & correct operation for the Keil C51 compiler.

    This is called Overlaying - it is Keil's solution to the problem that the 8051 has virtually no stack to speak of.

    Overlaying achieves at build-time what "normal" compilers achieve at run-time by using the stack.

Children