这是ADS build 805版的一个BUG!
到ARM公司网站上下一个848版的补丁就好了!是805版编译器的一个BUG! 做了以下两程序的测试: 程序1 文件名test1.c int test(unsigned int d) { if((d & 0x0fffffff) == 0x05555550) return 1; else return 0; }
int main(void) { volatile int d;
d = test(0xA5555550);
return d; } 在805版编译器下编译,生成test1b805.s: (armcc -O1 -S -fs -cpu ARM7TDMI -o test1b805.s test1.c)
; generated by ARM C Compiler, ADS1.2 [Build 805]
; commandline [-O1 -S -fs "-IC:Program FilesARMADSv1_2INCLUDE"] CODE32
AREA ||.text||, CODE, READONLY
test PROC ;;;1 int test(unsigned int d) ;;;2 { 000000 e59f1020 LDR r1,|L1.40| ;;;3 if((d & 0x0fffffff) == 0x05555550) 000004 e1a00200 MOV r0,r0,LSL #4 000008 e1500221 CMP r0,r1,LSR #4 00000c 1a000001 BNE |L1.24| ;;;4 return 1; 000010 e3a00001 MOV r0,#1 |L1.20| 000014 e1a0f00e MOV pc,lr ;;;5 else ;;;6 return 0; |L1.24| 000018 e3a00000 MOV r0,#0 00001c eafffffc B |L1.20| ;;;7 } ENDP
main PROC ;;;9 int main(void) ;;;10 { 000020 e59f0004 LDR r0,|L1.44| ;;;11 volatile int d; ;;;12 ;;;13 d = test(0xA5555550); 000024 eafffffe B test |L1.40| 000028 05555550 DCD 0x05555550 |L1.44| 00002c a5555550 DCD 0xa5555550 ;;;14 ;;;15 return d; ;;;16 } ENDP
END
在848版下编译生成test1b848.s (armcc -O1 -S -fs -cpu ARM7TDMI -o test1b848.s test1.c) ; generated by ARM C Compiler, ADS1.2 [Build 848]
; commandline [-O1 -S -fs "-IC:Program FilesARMADSv1_2INCLUDE"] CODE32
AREA ||.text||, CODE, READONLY
test PROC ;;;1 int test(unsigned int d) ;;;2 { 000000 e59f1020 LDR r1,|L1.40| ;;;3 if((d & 0x0fffffff) == 0x05555550) 000004 e1a00200 MOV r0,r0,LSL #4 000008 e1510220 CMP r1,r0,LSR #4 00000c 1a000001 BNE |L1.24| ;;;4 return 1; 000010 e3a00001 MOV r0,#1 |L1.20| 000014 e1a0f00e MOV pc,lr ;;;5 else ;;;6 return 0; |L1.24| 000018 e3a00000 MOV r0,#0 00001c eafffffc B |L1.20| ;;;7 } ENDP
main PROC ;;;9 int main(void) ;;;10 { 000020 e59f0004 LDR r0,|L1.44| ;;;11 volatile int d; ;;;12 ;;;13 d = test(0xA5555550); 000024 eafffffe B test |L1.40| 000028 05555550 DCD 0x05555550 |L1.44| 00002c a5555550 DCD 0xa5555550 ;;;14 ;;;15 return d; ;;;16 } ENDP
END
用UEDIT比较一下两个文件,生成的代码除一行不同外,其它的都一样(包括地址也一样),不同的一行是 000008 e1500221 CMP r0,r1,LSR #4 ;805版 000008 e1510220 CMP r1,r0,LSR #4 ;848版
第二个测试程序: 文件名:test2.c #include "stdio.h"
int test(unsigned int d) { if((d & 0x0fffffff) == 0x05555550) return 1; else return 0; }
int main(void) { volatile int d, c; scanf("%d",&d); d = test(d); c = 2 * d; printf("
d=%d
c=%d
",d,c); return c; }
在805版编译器下编译,生成test1b805.s: (armcc -O1 -S -fs -cpu ARM7TDMI -o test2b805.s test2.c) ; generated by ARM C Compiler, ADS1.2 [Build 805]
; commandline [-O1 -S -fs "-IC:Program FilesARMADSv1_2INCLUDE"] CODE32
AREA ||.text||, CODE, READONLY
test PROC ;;;3 int test(unsigned int d) ;;;4 { 000000 e59f1054 LDR r1,|L1.92| ;;;5 if((d & 0x0fffffff) == 0x05555550) 000004 e1a00200 MOV r0,r0,LSL #4 000008 e1500221 CMP r0,r1,LSR #4 00000c 1a000001 BNE |L1.24| ;;;6 return 1; 000010 e3a00001 MOV r0,#1 |L1.20| 000014 e1a0f00e MOV pc,lr ;;;7 else ;;;8 return 0; |L1.24| 000018 e3a00000 MOV r0,#0 00001c eafffffc B |L1.20| ;;;9 } ENDP
main PROC ;;;11 int main(void) ;;;12 { 000020 e92d401c STMFD sp!,{r2-r4,lr} ;;;13 volatile int d, c; ;;;14 ;;;15 scanf("%d",&d); 000024 e28d1004 ADD r1,sp,#4 000028 e28f0030 ADR r0,|L1.96| 00002c ebfffffe BL _scanf ;;;16 d = test(d); 000030 e59d0004 LDR r0,[sp,#4] 000034 ebfffffe BL test 000038 e58d0004 STR r0,[sp,#4] ;;;17 ;;;18 c = 2 * d; 00003c e59d0004 LDR r0,[sp,#4] 000040 e1a04080 MOV r4,r0,LSL #1 ;;;19 printf("
d=%d
c=%d
",d,c); 000044 e1a02004 MOV r2,r4 000048 e59d1004 LDR r1,[sp,#4] 00004c e28f0010 ADR r0,|L1.100| 000050 ebfffffe BL _printf ;;;20 ;;;21 return c; 000054 e1a00004 MOV r0,r4 000058 e8bd801c LDMFD sp!,{r2-r4,pc} |L1.92| 00005c 05555550 DCD 0x05555550 |L1.96| 000060 00006425 DCB "%d " |L1.100| 000064 253d640a DCB "
d=%" 000068 630a2064 DCB "d
c" 00006c 0a64253d DCB "=%d
" 000070 00000000 DCB " |
|