analysis code(value passing, pointer(address) passing)

1. none change

1.1)

int a = 9;

int add1(int a,int b)
{
    a = a + 1;
}

push ebp
      mov  ebp,esp
      mov  eax,dword ptr ss:[ebp+8]
      add  eax,1

      mov dword prt ss:[ebp+8], eax

here only change temp stack's [ebp+8] location's value.

after invoke the function add1, the stack will be recovery, and the [ebp+8] location's value will has none meaning.

So the a still is not changed, it is 9.

 
 1.2)

void cstart(int a,int b,int c)
{
 a=1;
 c=3;
 b=2;
}

call .**********(该函数的地址)           ;esp=0x00011800

push ebp                                  ;esp=0x000117fc

mov ebp,esp                              ;esp=0x000117f8,ebp=0x000117f8

mov dword ptr ss:[ebp+0x8], 0x00000001    ;esp=0x000117f8,ebp=0x000117f8

mov dword ptr ss:[ebp+0xc], 0x00000003   ;esp=0x000117f8,ebp=0x000117f8

mov dword ptr ss:[ebp+0x10], 0x00000002    ;esp=0x000117f8,ebp=0x000117f8

pop ebp

ret
汇编调用c函数时 <wbr>堆栈的变化的详细分析

 

2 pointer to value.

a has changed.

int i = 9;

int *a = &i;

int add1(int *a,int b)
{
    *a = *a + 1;
}

As it change the temp stack's [ebp+8] location's value(actually value address) """"ssss pointed value.

So this pointer is not change(in stack and exit stack it's the same).

alrough the pointer is same after exit invoking function,

But it's pointed value is followed to change as the temp stack's value's pointed NEW value.

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值