lesson21 函数在汇编中的过程

//lea取地址
//call 函数名(函数地址)

int bigernum = Greater(10, 100);

009616FE push 64h //传入第一个参数
00961700 push 0Ah //传入第二个参数
00961702 call _Greater (0961221h)
00961707 add esp,8
0096170A mov dword ptr [bigernum],eax //eax常用作函数的返回值bigernum为ebp-8,还原栈

int Greater(int first, int second)
{
008E1690 push ebp //压栈
008E1691 mov ebp,esp **//栈针指向**Greater函数
008E1693 sub esp,0C0h //esp-100,栈针
008E1699 push ebx
008E169A push esi
008E169B push edi
008E169C lea edi,[ebp-0C0h]
008E16A2 mov ecx,30h
008E16A7 mov eax,0CCCCCCCCh
008E16AC rep stos dword ptr es:[edi]
if (first>second)
008E16AE mov eax,dword ptr [first] //传递first是ebp+8
008E16B1 cmp eax,dword ptr [second]
008E16B4 jle Greater+2Dh (08E16BDh) //条件跳转
{
return first;
008E16B6 mov eax,dword ptr [first]
008E16B9 jmp Greater+30h (08E16C0h)
}
008E16BB jmp Greater+30h (08E16C0h)
else
return second;
008E16BD mov eax,dword ptr [second]
}

int Greater(int *first, int *second)
{
first = *second; //解引用操作,取出地址中的值**
*second = *first;
}

*first = *second;              //*解引用操作,取出地址中的值

009A16AE mov eax,dword ptr [first] //中扩号,取值操作first的值给eax
009A16B1 mov ecx,dword ptr [second]
009A16B4 mov edx,dword ptr [ecx]
009A16B6 mov dword ptr [eax],edx //edx的值赋值给eax所指向的值

int big = Greater(&first,&second);

01164156 lea eax,[second] //lea取地址给eax
01164159 push eax
0116415A lea ecx,[first]
0116415D push ecx
0116415E call _Greater (01161221h)
01164163 add esp,8
01164166 mov dword ptr [big],eax
return 0;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值