|
c51在keil中调试出现的问题,估计与编译有关,请教
[复制链接]
变量取值的问题
- void main()
- {
- unsigned int a1;
- unsigned int b1;
- unsigned char h;
- unsigned char l;
- a1=0xab12;
- l=a1;
- b1=(a1&0xff00)/256;
- h=b1;
- }
复制代码
用KEIL调试时发现,a1变量中的值没有赋成ab12h,而只是赋成0012h.程序改成如下后,a1的赋值就正确了:
- void main()
- {
- unsigned int a1;
- unsigned int b1;
- unsigned char h;
- unsigned char l;
- a1=0xab12;
- l=a1;
- a1=a1>>8;
- h=b1;
- }
复制代码
请教这是什么原因呢?
这个是反汇编的结果:
- 3:
- 4: unsigned int a1;
- 5: unsigned int b1;
- 6: unsigned char h;
- 7: unsigned char l;
- 8: a1=0xab12;
- 9: //l=(unsigned char)a;
- C:0x000F 7F12 MOV R7,#0x12
- C:0x0011 7EAB MOV R6,#0xAB
- 10: l=a1;
- 11: // b1=(a1&0xff00)/256;
- C:0x0013 8F0B MOV 0x0B,R7
- 12: a1=a1>>8;
- 13: // h=(unsigned char)a;
- C:0x0015 EE MOV A,R6
- 14: h=a1;
- 15:
- C:0x0016 F50A MOV 0x0A,A
- 16: }
- C:0x0018 22 RET
复制代码
如上,上述程序在编译时,多了这句:
C:0x0011 7EAB MOV R6,#0xAB
我是在keil uvision2是编译的。
|
|