我把下面这段代码放到keilc下编译:
typedef struct BitChar {
unsigned B0:1;
unsigned B1:1;
unsigned B2:1;
unsigned B3:1;
unsigned B4:1;
unsigned B5:1;
unsigned B6:1;
unsigned B7:1;
}SBitChar;
typedef union CharField{
unsigned char byte;
SBitChar field;
} UCharField;
void main(void)
{
struct BitChar key_state;
while(1)
{
key_state.B1 = 1;
key_state.B2 = 0;
key_state.B3 = 1;
}
}
编译的代码中主要为下面这些:
34: key_state.B1 = 1;
C:0x0003 850808 MOV 0x08,0x08
C:0x0006 E509 MOV A,0x09
C:0x0008 4402 ORL A,#0x02
C:0x000A F509 MOV 0x09,A
35: key_state.B2 = 0;
C:0x000C 850808 MOV 0x08,0x08
C:0x000F 54FB ANL A,#0xFB
C:0x0011 F509 MOV 0x09,A
36: key_state.B3 = 1;
C:0x0013 850808 MOV 0x08,0x08
C:0x0016 4408 ORL A,#0x08
C:0x0018 F509 MOV 0x09,A
其中有3跳 MOV 0x08,0x08
不知道这条语句是什么作用?
与或非是可以操作直接地址的,为什么要先MOV A,#0x8
另外,如果C语言中有key_state.B0 = key_state.B1 类似的操作,编译的代码就更大了.
不知道这是为什么? |