There are a lot of things which might cause different code patterns to be generated for bitfields. Just the ones which come to my mind now: - the number of bits (both times the same in your snippet) - the bit offset, especially bitoffsets 0 and 7 (least/most significant bits) may have special patterns - if the bitfield is volatile (I guess the PTAD_PTAD0 is) - how the bitfield is used, especially tests, assignments, ... - note that all your assignments have two bitfield accesses. - how to access the variables (DIRECT,...) - surrounding code (CSE, reuse of previously used computed subexpressions, available constants, common code opti, ...)
There are a lot of things which might cause different code patterns to be generated for bitfields. Just the ones which come to my mind now: - the number of bits (both times the same in your snippet) - the bit offset, especially bitoffsets 0 and 7 (least/most significant bits) may have special patterns - if the bitfield is volatile (I guess the PTAD_PTAD0 is) - how the bitfield is used, especially tests, assignments, ... - note that all your assignments have two bitfield accesses. - how to access the variables (DIRECT,...) - surrounding code (CSE, reuse of previously used computed subexpressions, available constants, common code opti, ...)
Do I misunderstand something ("my question is why PTAD_PTAD0 is not same as alm.two" )? This code do not try to set the port pin equal to alm.two, only sets alm.one equal to the port pin!
Do I misunderstand something ("my question is why PTAD_PTAD0 is not same as alm.two" )? This code do not try to set the port pin equal to alm.two, only sets alm.one equal to the port pin!
No, you are right. They are putting putting the value in alm.two into alm.one and then overwriting it with the status of PTAD_PTAD0. If they want PTAD_PTAD0 to be equal to alm.two they have to either:
1) Have PTAD_PTAD0 as an output then change the second line to
PTAD_PTAD0 = alm.one; // Set Port D Bit 0 to alm.one
or 2) Do the following:
alm.one = PTAD_PTAD0; // Set Port D Bit 0 to alm.one alm.two = alm.one; // Set alm.two to alm.one
Message Edited by allawtterb on 2008-01-2908:25 PM
I did understand the OP's question as why the compiler would generate different code for the two assignments, and not why the values of the port and the alm.two bitfield member were not the same. The latter are of course not the same as they are completely independent.
this snippet is for testing OPTION of compiler, and dont have real effect. in fact,I want asm code like this: BRSET 1,alm,L6 BCLR 0,alm BRA L8 L6: BSET 0,alm L8:
BRSET 0,_PTAD,L61 BCLR 0,alm BRA L81 L61: BSET 0,alm L81: