ios中C函数的汇编理解

2017-12-13  本文已影响20人  一__谷__作气
int s = func(1, 2, 3, 3, 4, 5);

int func(int a, int b, int c, int d, int e, int f)
{
    int g = a + b + c + d + e + f;
    return g;
}

一个简单的累加求和的函数

汇编如下

myAssembly2`func:
->  0x100076784 <+0>:  sub    sp, sp, #32               ; =32 分配栈空间
    0x100076788 <+4>:  str    w0, [sp, #28]   a               w0入栈
    0x10007678c <+8>:  str    w1, [sp, #24]   b               w1入栈
    0x100076790 <+12>: str    w2, [sp, #20]   c                 .
    0x100076794 <+16>: str    w3, [sp, #16]   d                 .
    0x100076798 <+20>: str    w4, [sp, #12]   e                 .
    0x10007679c <+24>: str    w5, [sp, #8]    f                 .
    0x1000767a0 <+28>: ldr    w0, [sp, #28]                  w0赋值(出栈)
    0x1000767a4 <+32>: ldr    w1, [sp, #24]                  w1赋值(出栈)
    0x1000767a8 <+36>: add    w0, w0, w1                     相加
    0x1000767ac <+40>: ldr    w1, [sp, #20]                  w1重新赋值(出栈)
    0x1000767b0 <+44>: add    w0, w0, w1                     相加
    0x1000767b4 <+48>: ldr    w1, [sp, #16]                    .(出栈)
    0x1000767b8 <+52>: add    w0, w0, w1                       .
    0x1000767bc <+56>: ldr    w1, [sp, #12]                    .(出栈)
    0x1000767c0 <+60>: add    w0, w0, w1                       .
    0x1000767c4 <+64>: ldr    w1, [sp, #8]                     .(出栈)
    0x1000767c8 <+68>: add    w0, w0, w1                       .
    0x1000767cc <+72>: str    w0, [sp, #4]     g              返回值
    0x1000767d0 <+76>: ldr    w0, [sp, #4]                    (出栈)
    0x1000767d4 <+80>: add    sp, sp, #32               ; =32 回收栈空间
    0x1000767d8 <+84>: ret                                     结束

上一篇下一篇

猜你喜欢

热点阅读