昔日,niuniu1983 “KEIL C 编译器的问题 ”的贴子提出的有关C51编译器的调试问题引人入胜,“C51真的那么逊吗?”实验一下。见下面模拟实验程序:
#include <reg51.h> #define uchar unsigned char
uchar led_dly_table[10]={1,2,3,4,5,6,7,8,9};
void led_dly_one_byte(uchar , bit ) ;
void main(void) { while(1); } //--------------------------------------------------------------
void time0_over_int(void)interrupt 1 using 3 { uchar i ; //
TR0 = 0; TL0 = i; //TH0 = i>>8; TR0 = 1;
led_dly_one_byte(5,1); }
//--------------------------------------------------------
void led_dly_one_byte(uchar number, bit dp) { uchar i;
i=led_dly_table[number]; if(dp) i&=0x7f; } ___________________________________________________________
keil下编译之:
C51 COMPILER V6.23a REENT 05/03/2008 09:17:16 PAGE 4
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION main (BEGIN) ; SOURCE LINE # 11 ; SOURCE LINE # 12 0000 ?C0001: ; SOURCE LINE # 14 ; SOURCE LINE # 15 ; SOURCE LINE # 17 0000 80FE SJMP ?C0001 ; FUNCTION main (END)
; FUNCTION time0_over_int (BEGIN) 0000 C0E0 PUSH ACC 0002 C0F0 PUSH B 0004 C083 PUSH DPH 0006 C082 PUSH DPL 0008 C0D0 PUSH PSW 000A 75D018 MOV PSW,#018H ; SOURCE LINE # 20 ; SOURCE LINE # 24 000D C28C CLR TR0 ; SOURCE LINE # 25 000F 85008A R MOV TL0,i ; SOURCE LINE # 27 0012 D28C SETB TR0 ; SOURCE LINE # 29 0014 D200 R SETB ?_led_dly_one_byte?BIT 0016 7F05 MOV R7,#05H 0018 120000 R LCALL _led_dly_one_byte ; SOURCE LINE # 30 001B D0D0 POP PSW 001D D082 POP DPL 001F D083 POP DPH 0021 D0F0 POP B 0023 D0E0 POP ACC 0025 32 RETI ; FUNCTION time0_over_int (END)
; FUNCTION _led_dly_one_byte (BEGIN) ; SOURCE LINE # 34 ;---- Variable 'number' assigned to Register 'R7' ---- ; SOURCE LINE # 35 ; SOURCE LINE # 37 ;---- Variable 'i' assigned to Register 'R7' ---- ; SOURCE LINE # 38 ; SOURCE LINE # 41 0000 ?C0006: 0000 22 RET ; FUNCTION _led_dly_one_byte (END)
令人诧异的编译结果,函数_led_dly_one_byte 根本没有被编译!
问题在哪 ?
顺便致谢niuniu1983 ,要不是他提出的精彩问题,也许我还会一直错过欣赏C51一道漂亮的风景。
|