33,311
社区成员
发帖
与我相关
我的任务
分享
#define SIZE 200
void test1(int);
void test2(int);
void test3(int);
void a()
{
int a[SIZE];
int i=0;
for(; i < SIZE; i++)
{
test1(a[i]);
/* test2(a[i]);
* test3(a[i]);
*/
}
}
void b()
{
int a[SIZE];
int *p = a;
int *pend = a+SIZE;
for(; p != pend; p++)
{
test1(*p);
/* test2(*p);
* test3(*p);
*/
}
}
_a:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $820, %esp
xorl %ebx, %ebx
.p2align 4,,15
L5: // 函数a中的for循环开始 这里实际上被优化为do……while循环
movl -808(%ebp,%ebx,4), %eax // 把a[i]的值放到寄存器%eax中 MARK
incl %ebx // i++;
movl %eax, (%esp) // 把a[i]当作参数压入栈
call _test1 // 调用函数test1
cmpl $199, %ebx // 比较i 和 199
jle L5 // 如果比较结果是否小于等于等于跳回L5
addl $820, %esp
popl %ebx
popl %ebp
ret
.p2align 4,,15
.globl _b
.def _b; .scl 2; .type 32; .endef
_b:
pushl %ebp
movl %esp, %ebp
pushl %esi
leal -8(%ebp), %esi
pushl %ebx
subl $816, %esp
leal -808(%ebp), %ebx
.p2align 4,,15
L13: // 函数b 中的for循环开始 这里同样被优化为do……while循环
movl (%ebx), %eax // 把指针p指向的值放到寄存器%eax中 MARK
addl $4, %ebx // 指针p 加4 (4 == sizeof(int) )
movl %eax, (%esp) // 把指针p指向的值压入栈
call _test1 // 调用函数test1
cmpl %esi, %ebx // 比较指针p 和pend
jne L13 // 如果不相等则返回L13(继续循环)
addl $816, %esp
popl %ebx
popl %esi
popl %ebp
ret
#include<stdio.h>
void main()
{
int i;
int a[10]={10, 20};
printf("%d\n",1);
printf("%d\n",a[0]);
printf("%d\n",a[1]); //*****************使用下标法
printf("%d\n",*a); //*****************指针法
printf("%d\n",*(a+1)); //*****************这几句话的汇编代码
printf("%d\n",2);
}