【arm】——一段加法程序的汇编注释

c code

int add4(int i, int j){     // 3,4
    int res = 10;
    int res2 = 11;
    asm volatile(
        "add %0, %1, %2    \n"
        // "str w0, %1        \n"
        :"=r"(res)           // 3
        :"r"(i),
        "r"(j)              // 4
        :
    );
    printf("res:%d, res2 value:%d, j:%d \n", res, res2, j);
    return res;
}
                                        
extern int myadd(int a, int b);
                                        
int main()
{       
        printf("Adding 00: %d+%d results in %d\n", 4, 4, add4(3, 4));
        return (0);
}

汇编注释

00000000000007b8 <add4>:
 7b8:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
 7bc:	910003fd 	mov	x29, sp
 7c0:	b9001fa0 	str	w0, [x29, #28]      // 3:[28,32], 第一个参数先入栈
 7c4:	b9001ba1 	str	w1, [x29, #24]      // 4:[24,28]
 7c8:	52800140 	mov	w0, #0xa                   	// #10
 7cc:	b9002ba0 	str	w0, [x29, #40]      // 10:[40,44]
 7d0:	52800160 	mov	w0, #0xb                   	// #11
 7d4:	b9002fa0 	str	w0, [x29, #44]      // 11:[44,48]
 7d8:	b9401fa0 	ldr	w0, [x29, #28]      // w0=3
 7dc:	b9401ba1 	ldr	w1, [x29, #24]      // w1=4
 7e0:	8b010000 	add	x0, x0, x1          // x0=3+4=7
 7e4:	b9002ba0 	str	w0, [x29, #40]      // 7写入res的位置:[40,44]
 7e8:	90000000 	adrp	x0, 0 <_init-0x598>
 7ec:	9123c000 	add	x0, x0, #0x8f0      // 前面都已经入栈了,这里只需要提取就好了,从右到左提取的
 7f0:	b9401ba3 	ldr	w3, [x29, #24]      // w3=4
 7f4:	b9402fa2 	ldr	w2, [x29, #44]      // w2=11
 7f8:	b9402ba1 	ldr	w1, [x29, #40]      // w1=7
 7fc:	97ffff85 	bl	610 <printf@plt>    // 跳转到 printf 函数
 800:	b9402ba0 	ldr	w0, [x29, #40]
 804:	a8c37bfd 	ldp	x29, x30, [sp], #48
 808:	d65f03c0 	ret
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值