C代码:
int sum6(int a,int b, int c, int d, int e, int f)
{
return (a+b+c+d+e+f);
}
int main()
{
int x,y,z;
y = 2;
x = 1;
y =sum6(1,2,3,4,5,6);
z = x + y;
return 0;
}
用ADS编译时,去掉编译选项优化参数 -O1
下面是相应的汇编代码,省去了__main到main部分的汇编代码
sum6 [0xe92d4010] stmfd r13!,{r4,r14}
000080ac [0xe1a04000] mov r4,r0
000080b0 [0xe28de008] add r14,r13,#8
000080b4 [0xe89e5000] ldmia r14,{r12,r14}
000080b8 [0xe0840001] add r0,r4,r1
000080bc [0xe0800002] add r0,r0,r2
000080c0 [0xe0800003] add r0,r0,r3
000080c4 [0xe080000c] add r0,r0,r12
000080c8 [0xe080000e] add r0,r0,r14
000080cc [0xe8bd8010] ldmfd r13!,{r4,pc}
main [0xe92d407c] * stmfd r13!,{r2-r6,r14}
000080d4 [0xe3a04002] mov r4,#2
000080d8 [0xe3a05001] mov r5,#1
000080dc [0xe3a03006] mov r3,#6
000080e0 [0xe3a02005] mov r2,#5
000080e4 [0xe88d000c] stmia r13,{r2,r3}
000080e8 [0xe3a03004] mov r3,#4
000080ec [0xe3a02003] mov r2,#3
000080f0 [0xe3a01002] mov r1,#2
000080f4 [0xe3a00001] mov r0,#1
000080f8 [0xebffffea] bl sum6
000080fc [0xe1a04000] mov r4,r0
00008100 [0xe0856004] add r6,r5,r4
00008104 [0xe3a00000] mov r0,#0
00008108 [0xe8bd807c] ldmfd r13!,{r2-r6,pc}
在进入main处,首先把{r2-r6,r14}寄存器压栈,但是在000080e4地址处,
指令stmia r13,{r2,r3}又使栈中r2,r3处的内容被新的r2,r3的内
容所更新,在main函数返回处00008108指令代码
ldmfd r13!,{r2-r6,pc}把r2,r3恢复,但是此时的r2,r3中的内容已经
不是刚进入main时的r2,r3内容。不知我分析的对否,请高手指点!