Hi, I want to know the address of a bit variable. For example:
bit gBit; func() { printf("%d", &gBit); }
Of course it can be done in 8051 otherwise how the compiler initialize all the global bit variables before the main function is called? When your program is compiled and linked, Keil C will build a data structure called C_INITSEG. This data structure stores all the global variables that need to be initialized before the main function is called. So it also records all the addresses of bit variables that need to initialized before the main function is called. By using this address of the bit variable, it can give the bit variable initial value.
If you're so sure of your understanding, why don't you just go ahead an look into C_INITSEG to check what the compiler actually does? Or tell me the opcode of the machine instruction accessing a bit indirectly?
If I read this correctly, the OP is of the school where it is taught "If you use a global address, you will die" Access to a bit in main and an interrupt can be accomplished simply by making the bit declaration global. Erik
So it also records all the addresses of bit variables that need to initialized before the main function is called. By using this address of the bit variable, it can give the bit variable initial value. The initialization code converts the bit address into a byte.bit address and then uses and and or to mask and set the bit accordingly. There is no instruction on the 8051 that supports indirect access to bits. It has to be done manually. Jon
The initialization code converts the bit address into a byte.bit address and then uses and and or to mask and set the bit accordingly Jon, you scared me there. I had a look and GBvfdBusy = TRUE; does, indeed, compile to SETB GBvfdBusy wiping sweat off forhead Erik
I'm talking about global bit variable initialization. We would never do something like this for local bit initialization (which use the SETB and CLR instructions). Jon
my example above IS a global bit.
Just got it two statements in one heap the bit address is converted into a byte.bit address before it is used The initialization code ... uses and and or to mask and set the bit accordingly