一段简单程序从汇编看C指针

首先需要明白的两个概念:

    指针:普通变量的地址
    指针变量:该变量内存放的是指针

程序分析如下:

#include<stdio.h>
void main(){
int a,b;
a = 10;
b = 100;
int *pointa,*pointb; //声明  *只是表示指针类型 int表示只能指向长度为4字节的int类型
pointa = &a;   //指针存放地址,&取地址
pointb = &b;
printf("%d,%d\n",a,b);
printf("%d,%d\n",*pointa,*pointb);  // *表示去内容,和声明时*含义不同(注意区分)
}

@ILT+0(_main):
00401005   jmp         main (00401010)  //main作为跳转首地址
0040100A   int         3  //类型3(专用:断点中断)中断   机器码0cch 是留给调试工具使用的中断
0040100B   int         3
0040100C   int         3
0040100D   int         3
0040100E   int         3
0040100F   int         3
--- C:\point.cpp  -----------------------------------------------------------------------------------------------------------------

1:    #include<stdio.h>
2:
3:    void main(){    //调用main  保存原寄存器内容  入栈操作
00401010   push        ebp
00401011   mov         ebp,esp
00401013   sub         esp,50h
00401016   push        ebx
00401017   push        esi
00401018   push        edi
00401019   lea         edi,[ebp-50h]
0040101C   mov         ecx,14h
00401021   mov         eax,0CCCCCCCCh
00401026   rep stos    dword ptr [edi]
4:        int a,b;
5:        a = 10;
00401028   mov         dword ptr [ebp-4],0Ah   //局部变量在不同环境下存放不同内存(即可马上销毁)  入栈ss
6:        b = 100;
0040102F   mov         dword ptr [ebp-8],64h
7:        int *pointa,*pointb;
8:        pointa = &a;
00401036   lea         eax,[ebp-4]   //取局部变量a的偏移地址给eax(int 4字节)
00401039   mov         dword ptr [ebp-0Ch],eax  
9:        pointb = &b;
0040103C   lea         ecx,[ebp-8]
0040103F   mov         dword ptr [ebp-10h],ecx
10:       printf("%d,%d\n",a,b);
00401042  mov         edx,dword ptr [ebp-8] //从右到左依此入栈
00401045  push        edx
00401046   mov         eax,dword ptr [ebp-4]
00401049   push        eax
0040104A   push        offset string "%d,%d\n" (0042201c)
0040104F   call        printf (004010a0) //系统调用  004010a0和下面系统调用统一操作
00401054   add         esp,0Ch
11:       printf("%d,%d\n",*pointa,*pointb);
00401057   mov         ecx,dword ptr [ebp-10h] //取地址 给ecx
0040105A   mov         edx,dword ptr [ecx]  //取值 ecx存在要取的值的地址
0040105C   push        edx
0040105D   mov         eax,dword ptr [ebp-0Ch]
00401060   mov         ecx,dword ptr [eax]
00401062   push        ecx
00401063   push        offset string "%d,%d\n" (0042201c)
00401068   call        printf (004010a0)
0040106D   add         esp,0Ch
12:   }
00401070   pop         edi    //恢复现场
00401071   pop         esi
00401072   pop         ebx
00401073   add         esp,50h
00401076   cmp         ebp,esp
00401078   call        __chkesp (00401120)
0040107D   mov         esp,ebp
0040107F   pop         ebp
00401080   ret

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值