发现点问题,EVC编译器造成的:
EVC4 SP4下,X86的编译器对于那个int*指针表达式从右到左计算,char型的表达式从左到右,晕
ARM下都是一个样,从右向左!
具体参看汇编码:
int* 型表达式,ARM汇编
233: int a[] = {1, 2, 3, 4};
26013FB0 mov r0, #1
26013FB4 str r0, [sp, #8]
26013FB8 mov r1, #2
26013FBC str r1, [sp, #0xC]
26013FC0 mov r0, #3
26013FC4 str r0, [sp, #0x10]
26013FC8 mov r1, #4
26013FCC str r1, [sp, #0x14]
234: int* p = a;
26013FD0 add r0, sp, #8
26013FD4 str r0, [sp]
235: int b = *p + *++p;
26013FD8 ldr r1, [sp]
26013FDC add r0, r1, #4 ; 先给指针加4
26013FE0 str r0, [sp]
26013FE4 ldr r1, [sp]
26013FE8 ldr r0, [r1] ;把加之后的值放入r0
26013FEC ldr r2, [sp]
26013FF0 ldr r1, [r2] ;取加之后的p值
26013FF4 add r3, r0, r1 ;求和
26013FF8 str r3, [sp, #0x18]
int* 型表达式,X86汇编
233: int a[] = {1, 2, 3, 4};
240137D6 mov dword ptr [a],1
240137DD mov dword ptr [ebp-10h],2
240137E4 mov dword ptr [ebp-0Ch],3
240137EB mov dword ptr [ebp-8],4
234: int* p = a;
240137F2 lea eax,[a]
240137F5 mov dword ptr [p],eax
235: int b = *p + *++p;
240137F8 mov ecx,dword ptr [p]
240137FB add ecx,4 ; 先给P增加4
240137FE mov dword ptr [p],ecx
24013801 mov edx,dword ptr [p]
24013804 mov eax,dword ptr [edx] ;把加之后的值放入eax
24013806 mov ecx,dword ptr [p] ;同样是加之后的P值放入ecx
24013809 add eax,dword ptr [ecx] ;求和
2401380B mov dword ptr [b],eax
236:
char* 型表达式,X86汇编
233: char a[] = {1, 2, 3, 4};
240137D6 mov byte ptr [a],1
240137DA mov byte ptr [ebp-7],2
240137DE mov byte ptr [ebp-6],3
240137E2 mov byte ptr [ebp-5],4
234: char* p = a;
240137E6 lea eax,[a]
240137E9 mov dword ptr [p],eax
235: char b = *p + *++p;
240137EC mov ecx,dword ptr [p]
240137EF movsx edx,byte ptr [ecx] ; 先把P值取出
240137F2 mov eax,dword ptr [p]
240137F5 add eax,1 ;再增加1
240137F8 mov dword ptr [p],eax
240137FB mov ecx,dword ptr [p]
240137FE movsx eax,byte ptr [ecx]
24013801 add edx,eax ;把最早保存的值和加1后的加起来
24013803 mov byte ptr [b],dl
236:
char* 型表达式,ARM汇编
233: char a[] = {1, 2, 3, 4};
26013FB0 mov r0, #1
26013FB4 strb r0, [sp, #4]
26013FB8 mov r1, #2
26013FBC strb r1, [sp, #5]
26013FC0 mov r0, #3
26013FC4 strb r0, [sp, #6]
26013FC8 mov r1, #4
26013FCC strb r1, [sp, #7]
234: char* p = a;
26013FD0 add r0, sp, #4
26013FD4 str r0, [sp]
235: char b = *p + *++p;
26013FD8 ldr r1, [sp]
26013FDC add r0, r1, #1 ; 先P地址加1
26013FE0 str r0, [sp]
26013FE4 ldr r1, [sp]
26013FE8 ldrsb r0, [r1]
26013FEC ldr r1, [sp]
26013FF0 ldrsb r2, [r1]
26013FF4 add r1, r2, r0
26013FF8 mov r3, r1, lsl #24
26013FFC mov r0, r3, asr #24
26014000 strb r0, [sp, #8]
不知道是不是微软EVC编译器的问题,从开始编程至今我一直倾向于从右向左 :)
好久没有写BLOG了,一直忙于项目,今天来冒个泡泡