本帖最后由 ssmm1228 于 2018-5-22 15:56 编辑
项目使用M451LC3AE芯片。
有一段函数,c语言写的。选择Level 0优化时,程序运行正常,选择Level 3优化时,程序运行出错。现奉上c函数以及两种优化下的反汇编函数,请各位帮忙分析下原因。
c函数
/****************************************
*函数名称:CheckEmitterLEDNumber
*输 入:无
*输 出:无
*功 能:检查接板数量及LED灯数量
******************************************/
void CheckEmitterLEDNumber()
{
uchar i = 0,j = 0;
uint CheckSum16 = 0;
//询问接板是否在线及数量
for(i=0;i<20;i++)PBLedNumber=0;
for(i=0;i<20;i++)
{
PBTxDataBuf[0]=0x5A;
PBTxDataBuf[1]=i+1;
PBTxDataBuf[2]=0x00;
PBTxDataBuf[3]=0x00;
PBTxDataBuf[4]=0x00;
PBTxDataBuf[5]=0x00;
PBTxDataBuf[6]=0x00;
CheckSum16 = 0;
for(j=0;j<7;j++)CheckSum16+=PBTxDataBuf[j];
CheckSum16 = 0xFFFF - CheckSum16;
PBTxDataBuf[7]=CheckSum16%256;
PBTxDataBuf[8]=CheckSum16/256;
UART_Write(UART1,(uchar *)PBTxDataBuf,9);
PBRRxDataLen=0;
Time10usCnt=0;
while(Time10usCnt<200)
{
__nop();
}
if(PBRRxDataLen>5)
{
if(PBRRxDataBuf[0]==0x5A && PBRRxDataBuf[1]==i+1)
{
CheckSum16 = 0;
for(j=0;j<7;j++)CheckSum16+=PBRRxDataBuf[j];
CheckSum16 = 0xFFFF - CheckSum16;
if(CheckSum16 == PBRRxDataBuf[8]*256 + PBRRxDataBuf[7])
{
PBLedNumber=PBRRxDataBuf[2];
}
}
}
}
PBLedNumberAll = 0;
for(i=0;i<20;i++)PBLedNumberAll+=PBLedNumber;
UART_DisableInt(UART1, UART_INTEN_RDAIEN_Msk); //发送完毕,关闭串口1接收中断
if(PBLedNumberAll!=EmitterChannelNumber)
{
EmitterSysStatus |= B00001000; //bit3:接板故障,通道数不正确
}
PanelDIG3 = PBLedNumberAll/100;
PanelDIG2 = PBLedNumberAll%100/10;
PanelDIG1 = PBLedNumberAll%10;
EmitterLEDDisplayFresh();
}
Level 0优化下的反汇编函数
i.CheckEmitterLEDNumber
CheckEmitterLEDNumber
0x000008dc: b570 p. PUSH {r4-r6,lr}
0x000008de: 2500 .% MOVS r5,#0
0x000008e0: 2600 .& MOVS r6,#0
0x000008e2: 2400 .$ MOVS r4,#0
0x000008e4: bf00 .. NOP
0x000008e6: e004 .. B 0x8f2 ; CheckEmitterLEDNumber + 22
0x000008e8: 2000 . MOVS r0,#0
0x000008ea: 4953 SI LDR r1,[pc,#332] ; [0xa38] = 0x200000f0
0x000008ec: 5548 HU STRB r0,[r1,r5]
0x000008ee: 1c68 h. ADDS r0,r5,#1
0x000008f0: b2c5 .. UXTB r5,r0
0x000008f2: 2d14 .- CMP r5,#0x14
0x000008f4: dbf8 .. BLT 0x8e8 ; CheckEmitterLEDNumber + 12
0x000008f6: 2500 .% MOVS r5,#0
0x000008f8: e05e ^. B 0x9b8 ; CheckEmitterLEDNumber + 220
0x000008fa: 205a Z MOVS r0,#0x5a
0x000008fc: 494f OI LDR r1,[pc,#316] ; [0xa3c] = 0x200000b4
0x000008fe: 7008 .p STRB r0,[r1,#0]
0x00000900: 1c68 h. ADDS r0,r5,#1
0x00000902: 7048 Hp STRB r0,[r1,#1]
0x00000904: 2000 . MOVS r0,#0
0x00000906: 7088 .p STRB r0,[r1,#2]
0x00000908: 70c8 .p STRB r0,[r1,#3]
0x0000090a: 7108 .q STRB r0,[r1,#4]
0x0000090c: 7148 Hq STRB r0,[r1,#5]
0x0000090e: 7188 .q STRB r0,[r1,#6]
0x00000910: 2400 .$ MOVS r4,#0
0x00000912: 2600 .& MOVS r6,#0
0x00000914: e005 .. B 0x922 ; CheckEmitterLEDNumber + 70
0x00000916: 4849 IH LDR r0,[pc,#292] ; [0xa3c] = 0x200000b4
0x00000918: 5d80 .] LDRB r0,[r0,r6]
0x0000091a: 4420 D ADD r0,r0,r4
0x0000091c: b284 .. UXTH r4,r0
0x0000091e: 1c70 p. ADDS r0,r6,#1
0x00000920: b2c6 .. UXTB r6,r0
0x00000922: 2e07 .. CMP r6,#7
0x00000924: dbf7 .. BLT 0x916 ; CheckEmitterLEDNumber + 58
0x00000926: f64f70ff O..p MOV r0,#0xffff
0x0000092a: 1b04 .. SUBS r4,r0,r4
0x0000092c: 4620 F MOV r0,r4
0x0000092e: 17e1 .. ASRS r1,r4,#31
0x00000930: eb046111 ...a ADD r1,r4,r1,LSR #24
0x00000934: 1209 .. ASRS r1,r1,#8
0x00000936: eba42101 ...! SUB r1,r4,r1,LSL #8
0x0000093a: 4a40 @... LDR r2,[pc,#256] ; [0xa3c] = 0x200000b4
0x0000093c: 71d1 .q STRB r1,[r2,#7]
0x0000093e: 17e1 .. ASRS r1,r4,#31
0x00000940: eb046111 ...a ADD r1,r4,r1,LSR #24
0x00000944: 0a09 .. LSRS r1,r1,#8
0x00000946: 7211 .r STRB r1,[r2,#8]
0x00000948: 2209 ." MOVS r2,#9
0x0000094a: 493c <I LDR r1,[pc,#240] ; [0xa3c] = 0x200000b4
0x0000094c: 483c <H LDR r0,[pc,#240] ; [0xa40] = 0x40071000
0x0000094e: f001fcb7 .... BL UART_Write ; 0x22c0
0x00000952: 2000 . MOVS r0,#0
0x00000954: 493b ;I LDR r1,[pc,#236] ; [0xa44] = 0x20000012
0x00000956: 7008 .p STRB r0,[r1,#0]
0x00000958: 493b ;I LDR r1,[pc,#236] ; [0xa48] = 0x20000002
0x0000095a: 8008 .. STRH r0,[r1,#0]
0x0000095c: e000 .. B 0x960 ; CheckEmitterLEDNumber + 132
0x0000095e: bf00 .. NOP
0x00000960: 4839 9H LDR r0,[pc,#228] ; [0xa48] = 0x20000002
0x00000962: 8800 .. LDRH r0,[r0,#0]
0x00000964: 28c8 .( CMP r0,#0xc8
0x00000966: dbfa .. BLT 0x95e ; CheckEmitterLEDNumber + 130
0x00000968: 4836 6H LDR r0,[pc,#216] ; [0xa44] = 0x20000012
0x0000096a: 7800 .x LDRB r0,[r0,#0]
0x0000096c: 2805 .( CMP r0,#5
0x0000096e: dd21 !. BLE 0x9b4 ; CheckEmitterLEDNumber + 216
0x00000970: 4836 6H LDR r0,[pc,#216] ; [0xa4c] = 0x200000be
0x00000972: 7800 .x LDRB r0,[r0,#0]
0x00000974: 285a Z( CMP r0,#0x5a
0x00000976: d11d .. BNE 0x9b4 ; CheckEmitterLEDNumber + 216
0x00000978: 4834 4H LDR r0,[pc,#208] ; [0xa4c] = 0x200000be
0x0000097a: 7841 Ax LDRB r1,[r0,#1]
0x0000097c: 1c68 h. ADDS r0,r5,#1
0x0000097e: 4281 .B CMP r1,r0
0x00000980: d118 .. BNE 0x9b4 ; CheckEmitterLEDNumber + 216
0x00000982: 2400 .$ MOVS r4,#0
0x00000984: 2600 .& MOVS r6,#0
0x00000986: e005 .. B 0x994 ; CheckEmitterLEDNumber + 184
0x00000988: 4830 0H LDR r0,[pc,#192] ; [0xa4c] = 0x200000be
0x0000098a: 5d80 .] LDRB r0,[r0,r6]
0x0000098c: 4420 D ADD r0,r0,r4
0x0000098e: b284 .. UXTH r4,r0
0x00000990: 1c70 p. ADDS r0,r6,#1
0x00000992: b2c6 .. UXTB r6,r0
0x00000994: 2e07 .. CMP r6,#7
0x00000996: dbf7 .. BLT 0x988 ; CheckEmitterLEDNumber + 172
0x00000998: f64f70ff O..p MOV r0,#0xffff
0x0000099c: 1b04 .. SUBS r4,r0,r4
0x0000099e: 482b +H LDR r0,[pc,#172] ; [0xa4c] = 0x200000be
0x000009a0: 79c1 .y LDRB r1,[r0,#7]
0x000009a2: 7a00 .z LDRB r0,[r0,#8]
0x000009a4: eb012000 ... ADD r0,r1,r0,LSL #8
0x000009a8: 42a0 .B CMP r0,r4
0x000009aa: d103 .. BNE 0x9b4 ; CheckEmitterLEDNumber + 216
0x000009ac: 4827 'H LDR r0,[pc,#156] ; [0xa4c] = 0x200000be
0x000009ae: 7880 .x LDRB r0,[r0,#2]
0x000009b0: 4921 !I LDR r1,[pc,#132] ; [0xa38] = 0x200000f0
0x000009b2: 5548 HU STRB r0,[r1,r5]
0x000009b4: 1c68 h. ADDS r0,r5,#1
0x000009b6: b2c5 .. UXTB r5,r0
0x000009b8: 2d14 .- CMP r5,#0x14
0x000009ba: db9e .. BLT 0x8fa ; CheckEmitterLEDNumber + 30
0x000009bc: 2000 . MOVS r0,#0
0x000009be: 4924 $I LDR r1,[pc,#144] ; [0xa50] = 0x20000014
0x000009c0: 8008 .. STRH r0,[r1,#0]
0x000009c2: 2500 .% MOVS r5,#0
0x000009c4: e008 .. B 0x9d8 ; CheckEmitterLEDNumber + 252
0x000009c6: 481c .H LDR r0,[pc,#112] ; [0xa38] = 0x200000f0
0x000009c8: 5d40 @... LDRB r0,[r0,r5]
0x000009ca: 4921 !I LDR r1,[pc,#132] ; [0xa50] = 0x20000014
0x000009cc: 8809 .. LDRH r1,[r1,#0]
0x000009ce: 4408 .D ADD r0,r0,r1
0x000009d0: 491f .I LDR r1,[pc,#124] ; [0xa50] = 0x20000014
0x000009d2: 8008 .. STRH r0,[r1,#0]
0x000009d4: 1c68 h. ADDS r0,r5,#1
0x000009d6: b2c5 .. UXTB r5,r0
0x000009d8: 2d14 .- CMP r5,#0x14
0x000009da: dbf4 .. BLT 0x9c6 ; CheckEmitterLEDNumber + 234
0x000009dc: 2101 .! MOVS r1,#1
0x000009de: 4818 .H LDR r0,[pc,#96] ; [0xa40] = 0x40071000
0x000009e0: f001fbd8 .... BL UART_DisableInt ; 0x2194
0x000009e4: 481a .H LDR r0,[pc,#104] ; [0xa50] = 0x20000014
0x000009e6: 8800 .. LDRH r0,[r0,#0]
0x000009e8: 2848 H( CMP r0,#0x48
0x000009ea: d005 .. BEQ 0x9f8 ; CheckEmitterLEDNumber + 284
0x000009ec: 4819 .H LDR r0,[pc,#100] ; [0xa54] = 0x20000058
0x000009ee: 7800 .x LDRB r0,[r0,#0]
0x000009f0: f0400008 @... ORR r0,r0,#8
0x000009f4: 4917 .I LDR r1,[pc,#92] ; [0xa54] = 0x20000058
0x000009f6: 7008 .p STRB r0,[r1,#0]
0x000009f8: 4815 .H LDR r0,[pc,#84] ; [0xa50] = 0x20000014
0x000009fa: 8800 .. LDRH r0,[r0,#0]
0x000009fc: 2164 d! MOVS r1,#0x64
0x000009fe: fb90f0f1 .... SDIV r0,r0,r1
0x00000a02: 4915 .I LDR r1,[pc,#84] ; [0xa58] = 0x20000039
0x00000a04: 7008 .p STRB r0,[r1,#0]
0x00000a06: 4812 .H LDR r0,[pc,#72] ; [0xa50] = 0x20000014
0x00000a08: 8800 .. LDRH r0,[r0,#0]
0x00000a0a: 2164 d! MOVS r1,#0x64
0x00000a0c: fb90f2f1 .... SDIV r2,r0,r1
0x00000a10: fb010012 .... MLS r0,r1,r2,r0
0x00000a14: 210a .! MOVS r1,#0xa
0x00000a16: fb90f0f1 .... SDIV r0,r0,r1
0x00000a1a: 4910 .I LDR r1,[pc,#64] ; [0xa5c] = 0x20000038
0x00000a1c: 7008 .p STRB r0,[r1,#0]
0x00000a1e: 480c .H LDR r0,[pc,#48] ; [0xa50] = 0x20000014
0x00000a20: 8800 .. LDRH r0,[r0,#0]
0x00000a22: 210a .! MOVS r1,#0xa
0x00000a24: fb90f2f1 .... SDIV r2,r0,r1
0x00000a28: fb010012 .... MLS r0,r1,r2,r0
0x00000a2c: 490c .I LDR r1,[pc,#48] ; [0xa60] = 0x20000037
0x00000a2e: 7008 .p STRB r0,[r1,#0]
0x00000a30: f000fa62 ..b. BL EmitterLEDDisplayFresh ; 0xef8
0x00000a34: bd70 p. POP {r4-r6,pc}
$d
0x00000a36: 0000 .. DCW 0
0x00000a38: 200000f0 ... DCD 536871152
0x00000a3c: 200000b4 ... DCD 536871092
0x00000a40: 40071000 ...@ DCD 1074204672
0x00000a44: 20000012 ... DCD 536870930
0x00000a48: 20000002 ... DCD 536870914
0x00000a4c: 200000be ... DCD 536871102
0x00000a50: 20000014 ... DCD 536870932
0x00000a54: 20000058 X.. DCD 536871000
0x00000a58: 20000039 9.. DCD 536870969
0x00000a5c: 20000038 8.. DCD 536870968
0x00000a60: 20000037 7.. DCD 536870967
Level 3优化下的反汇编函数
i.CheckEmitterLEDNumber
CheckEmitterLEDNumber
0x00000818: e92d5ff0 -.._ PUSH {r4-r12,lr}
0x0000081c: 2000 . MOVS r0,#0
0x0000081e: 4f47 GO LDR r7,[pc,#284] ; [0x93c] = 0x200000c0
0x00000820: 4604 .F MOV r4,r0
0x00000822: 543c <T STRB r4,[r7,r0]
0x00000824: 1c40 @. ADDS r0,r0,#1
0x00000826: b2c0 .. UXTB r0,r0
0x00000828: 2814 .( CMP r0,#0x14
0x0000082a: d3fa .. BCC 0x822 ; CheckEmitterLEDNumber + 10
0x0000082c: f8dfa110 .... LDR r10,[pc,#272] ; [0x940] = 0x200000ac
0x00000830: f8df9110 .... LDR r9,[pc,#272] ; [0x944] = 0x20000002
0x00000834: f8dfb110 .... LDR r11,[pc,#272] ; [0x948] = 0x2000004f
0x00000838: 2500 .% MOVS r5,#0
0x0000083a: f64f78ff O..x MOV r8,#0xffff
0x0000083e: 215a Z! MOVS r1,#0x5a
0x00000840: 4650 PF MOV r0,r10
0x00000842: f88a1000 .... STRB r1,[r10,#0]
0x00000846: 1c6e n. ADDS r6,r5,#1
0x00000848: f88a6001 ...` STRB r6,[r10,#1]
0x0000084c: f88a4002 ...@ STRB r4,[r10,#2]
0x00000850: f88a4003 ...@ STRB r4,[r10,#3]
0x00000854: f88a4004 ...@ STRB r4,[r10,#4]
0x00000858: f88a4005 ...@ STRB r4,[r10,#5]
0x0000085c: f88a4006 ...@ STRB r4,[r10,#6]
0x00000860: 2200 ." MOVS r2,#0
0x00000862: 4611 .F MOV r1,r2
0x00000864: 5c43 C\ LDRB r3,[r0,r1]
0x00000866: 1c49 I. ADDS r1,r1,#1
0x00000868: 441a .D ADD r2,r2,r3
0x0000086a: b2c9 .. UXTB r1,r1
0x0000086c: b292 .. UXTH r2,r2
0x0000086e: 2907 .) CMP r1,#7
0x00000870: d3f8 .. BCC 0x864 ; CheckEmitterLEDNumber + 76
0x00000872: eba80102 .... SUB r1,r8,r2
0x00000876: 71c1 .q STRB r1,[r0,#7]
0x00000878: 0a09 .. LSRS r1,r1,#8
0x0000087a: 7201 .r STRB r1,[r0,#8]
0x0000087c: 2209 ." MOVS r2,#9
0x0000087e: 4930 0I LDR r1,[pc,#192] ; [0x940] = 0x200000ac
0x00000880: 4832 2H LDR r0,[pc,#200] ; [0x94c] = 0x40071000
0x00000882: f001fa59 ..Y. BL UART_Write ; 0x1d38
0x00000886: 4659 YF MOV r1,r11
0x00000888: f88b4000 ...@ STRB r4,[r11,#0]
0x0000088c: 4648 HF MOV r0,r9
0x0000088e: f8a94000 ...@ STRH r4,[r9,#0]
0x00000892: e000 .. B 0x896 ; CheckEmitterLEDNumber + 126
0x00000894: bf00 .. NOP
0x00000896: 8802 .. LDRH r2,[r0,#0]
0x00000898: 2ac8 .* CMP r2,#0xc8
0x0000089a: d3fb .. BCC 0x894 ; CheckEmitterLEDNumber + 124
0x0000089c: 7808 .x LDRB r0,[r1,#0]
0x0000089e: 2805 .( CMP r0,#5
0x000008a0: d919 .. BLS 0x8d6 ; CheckEmitterLEDNumber + 190
0x000008a2: 482b +H LDR r0,[pc,#172] ; [0x950] = 0x200000b6
0x000008a4: 7801 .x LDRB r1,[r0,#0]
0x000008a6: 295a Z) CMP r1,#0x5a
0x000008a8: d115 .. BNE 0x8d6 ; CheckEmitterLEDNumber + 190
0x000008aa: 7841 Ax LDRB r1,[r0,#1]
0x000008ac: 42b1 .B CMP r1,r6
0x000008ae: d112 .. BNE 0x8d6 ; CheckEmitterLEDNumber + 190
0x000008b0: 2200 ." MOVS r2,#0
0x000008b2: 4611 .F MOV r1,r2
0x000008b4: 5c43 C\ LDRB r3,[r0,r1]
0x000008b6: 1c49 I. ADDS r1,r1,#1
0x000008b8: 441a .D ADD r2,r2,r3
0x000008ba: b2c9 .. UXTB r1,r1
0x000008bc: b292 .. UXTH r2,r2
0x000008be: 2907 .) CMP r1,#7
0x000008c0: d3f8 .. BCC 0x8b4 ; CheckEmitterLEDNumber + 156
0x000008c2: eba80102 .... SUB r1,r8,r2
0x000008c6: 79c2 .y LDRB r2,[r0,#7]
0x000008c8: 7a03 .z LDRB r3,[r0,#8]
0x000008ca: eb022203 ..." ADD r2,r2,r3,LSL #8
0x000008ce: 428a .B CMP r2,r1
0x000008d0: d101 .. BNE 0x8d6 ; CheckEmitterLEDNumber + 190
0x000008d2: 7880 .x LDRB r0,[r0,#2]
0x000008d4: 5578 xU STRB r0,[r7,r5]
0x000008d6: b2f5 .. UXTB r5,r6
0x000008d8: 2d14 .- CMP r5,#0x14
0x000008da: d3b0 .. BCC 0x83e ; CheckEmitterLEDNumber + 38
0x000008dc: 4d1d .M LDR r5,[pc,#116] ; [0x954] = 0x20000010
0x000008de: 2000 . MOVS r0,#0
0x000008e0: 802c ,. STRH r4,[r5,#0]
0x000008e2: 5c39 9\ LDRB r1,[r7,r0]
0x000008e4: 882a *. LDRH r2,[r5,#0]
0x000008e6: 1c40 @. ADDS r0,r0,#1
0x000008e8: 4411 .D ADD r1,r1,r2
0x000008ea: b2c0 .. UXTB r0,r0
0x000008ec: 8029 ). STRH r1,[r5,#0]
0x000008ee: 2814 .( CMP r0,#0x14
0x000008f0: d3f7 .. BCC 0x8e2 ; CheckEmitterLEDNumber + 202
0x000008f2: 2101 .! MOVS r1,#1
0x000008f4: 4815 .H LDR r0,[pc,#84] ; [0x94c] = 0x40071000
0x000008f6: f001f9a3 .... BL UART_DisableInt ; 0x1c40
0x000008fa: 8829 ). LDRH r1,[r5,#0]
0x000008fc: 2948 H) CMP r1,#0x48
0x000008fe: d004 .. BEQ 0x90a ; CheckEmitterLEDNumber + 242
0x00000900: 4815 .H LDR r0,[pc,#84] ; [0x958] = 0x20000043
0x00000902: 7802 .x LDRB r2,[r0,#0]
0x00000904: f0420208 B... ORR r2,r2,#8
0x00000908: 7002 .p STRB r2,[r0,#0]
0x0000090a: 2064 d MOVS r0,#0x64
0x0000090c: fbb1f2f0 .... UDIV r2,r1,r0
0x00000910: 4b12 .K LDR r3,[pc,#72] ; [0x95c] = 0x20000035
0x00000912: 701a .p STRB r2,[r3,#0]
0x00000914: fbb1f2f0 .... UDIV r2,r1,r0
0x00000918: fb001212 .... MLS r2,r0,r2,r1
0x0000091c: 200a . MOVS r0,#0xa
0x0000091e: fbb2f2f0 .... UDIV r2,r2,r0
0x00000922: 4b0f .K LDR r3,[pc,#60] ; [0x960] = 0x20000034
0x00000924: 701a .p STRB r2,[r3,#0]
0x00000926: fbb1f2f0 .... UDIV r2,r1,r0
0x0000092a: fb001012 .... MLS r0,r0,r2,r1
0x0000092e: 490d .I LDR r1,[pc,#52] ; [0x964] = 0x20000033
0x00000930: 7008 .p STRB r0,[r1,#0]
0x00000932: e8bd5ff0 ..._ POP {r4-r12,lr}
0x00000936: f000b9e3 .... B.W EmitterLEDDisplayFresh ; 0xd00
$d
0x0000093a: 0000 .. DCW 0
0x0000093c: 200000c0 ... DCD 536871104
0x00000940: 200000ac ... DCD 536871084
0x00000944: 20000002 ... DCD 536870914
0x00000948: 2000004f O.. DCD 536870991
0x0000094c: 40071000 ...@ DCD 1074204672
0x00000950: 200000b6 ... DCD 536871094
0x00000954: 20000010 ... DCD 536870928
0x00000958: 20000043 C.. DCD 536870979
0x0000095c: 20000035 5.. DCD 536870965
0x00000960: 20000034 4.. DCD 536870964
0x00000964: 20000033 3.. DCD 536870963
|
|