一個(gè)從定時(shí)計(jì)數(shù)器賦初值引起的故事
程序變得非常龐大,代碼從28B猛增到169B:
C:0x0000 02009D LJMP C:009DC?SIDIV:C:0x0003 C2D5 CLR F0(0xD0.5)C:0x0005 EC MOV A,R4C:0x0006 30E709 JNB 0xE0.7,C:0012C:0x0009 B2D5 CPL F0(0xD0.5)C:0x000B E4 CLR AC:0x000C C3 CLR CC:0x000D 9D SUBB A,R5C:0x000E FD MOV R5,AC:0x000F E4 CLR AC:0x0010 9C SUBB A,R4C:0x0011 FC MOV R4,AC:0x0012 EE MOV A,R6C:0x0013 30E715 JNB 0xE0.7,C:002BC:0x0016 B2D5 CPL F0(0xD0.5)C:0x0018 E4 CLR AC:0x0019 C3 CLR CC:0x001A 9F SUBB A,R7C:0x001B FF MOV R7,AC:0x001C E4 CLR AC:0x001D 9E SUBB A,R6C:0x001E FE MOV R6,AC:0x001F 120039 LCALL C?UIDIV(C:0039)C:0x0022 C3 CLR CC:0x0023 E4 CLR AC:0x0024 9D SUBB A,R5C:0x0025 FD MOV R5,AC:0x0026 E4 CLR AC:0x0027 9C SUBB A,R4C:0x0028 FC MOV R4,AC:0x0029 8003 SJMP C:002EC:0x002B 120039 LCALL C?UIDIV(C:0039)C:0x002E 30D507 JNB F0(0xD0.5),C:0038C:0x0031 C3 CLR CC:0x0032 E4 CLR AC:0x0033 9F SUBB A,R7C:0x0034 FF MOV R7,AC:0x0035 E4 CLR AC:0x0036 9E SUBB A,R6C:0x0037 FE MOV R6,AC:0x0038 22 RET C?UIDIV:C:0x0039 BC000B CJNE R4,#0x00,C:0047C:0x003C BE0029 CJNE R6,#0x00,C:0068C:0x003F EF MOV A,R7C:0x0040 8DF0 MOV B(0xF0),R5C:0x0042 84 DIV ABC:0x0043 FF MOV R7,AC:0x0044 ADF0 MOV R5,B(0xF0)C:0x0046 22 RET C:0x0047 E4 CLR AC:0x0048 CC XCH A,R4C:0x0049 F8 MOV R0,AC:0x004A 75F008 MOV B(0xF0),#0x08C:0x004D EF MOV A,R7C:0x004E 2F ADD A,R7C:0x004F FF MOV R7,AC:0x0050 EE MOV A,R6C:0x0051 33 RLC AC:0x0052 FE MOV R6,AC:0x0053 EC MOV A,R4C:0x0054 33 RLC AC:0x0055 FC MOV R4,AC:0x0056 EE MOV A,R6C:0x0057 9D SUBB A,R5C:0x0058 EC MOV A,R4C:0x0059 98 SUBB A,R0C:0x005A 4005 JC C:0061C:0x005C FC MOV R4,AC:0x005D EE MOV A,R6C:0x005E 9D SUBB A,R5C:0x005F FE MOV R6,AC:0x0060 0F INC R7C:0x0061 D5F0E9 DJNZ B(0xF0),C:004DC:0x0064 E4 CLR AC:0x0065 CE XCH A,R6C:0x0066 FD MOV R5,AC:0x0067 22 RET C:0x0068 ED MOV A,R5C:0x0069 F8 MOV R0,AC:0x006A F5F0 MOV B(0xF0),AC:0x006C EE MOV A,R6C:0x006D 84 DIV ABC:0x006E 20D21C JB OV(0xD0.2),C:008DC:0x0071 FE MOV R6,AC:0x0072 ADF0 MOV R5,B(0xF0)C:0x0074 75F008 MOV B(0xF0),#0x08C:0x0077 EF MOV A,R7C:0x0078 2F ADD A,R7C:0x0079 FF MOV R7,AC:0x007A ED MOV A,R5C:0x007B 33 RLC AC:0x007C FD MOV R5,AC:0x007D 4007 JC C:0086C:0x007F 98 SUBB A,R0C:0x0080 5006 JNC C:0088C:0x0082 D5F0F2 DJNZ B(0xF0),C:0077C:0x0085 22 RET C:0x0086 C3 CLR CC:0x0087 98 SUBB A,R0C:0x0088 FD MOV R5,AC:0x0089 0F INC R7C:0x008A D5F0EA DJNZ B(0xF0),C:0077C:0x008D 22 RET
2: void main()
3: {
4: int i;
5: unsigned char j;
6: i=-10000;
7:
C:0x008E 7FF0 MOV R7,#B(0xF0)
C:0x0090 7ED8 MOV R6,#0xD8
8: j=i/256;
9:
C:0x0092 7C01 MOV R4,#0x01
C:0x0094 7D00 MOV R5,#0x00
C:0x0096 120003 LCALL C?SIDIV(C:0003)
C:0x0099 8F08 MOV 0x08,R7
10: while(1)
C:0x009B 80FE SJMP C:009B
就是一個(gè)signed和unsigned的區(qū)別,用的著差別這么大嗎?
通過以上的實(shí)驗(yàn),可以得出結(jié)論:Keil編譯器非常智能,會(huì)生成最短的代碼,能夠智能判斷每個(gè)變量的使用,生成最短的代碼。同時(shí),學(xué)習(xí)單片機(jī)的各位同仁,除非萬不得已,千萬不要用signed類型。
評論