C代码嵌套ARM汇编

基本结构如下

__asm [volatile] (code); /* Basic inline assembly syntax */
/* Extended inline assembly syntax */ 
__asm [volatile] (code_template 
       : output_operand_list 
      [: input_operand_list 
      [: clobbered_register_list]] 
  );

其中,
code 是汇编指令, 例如 “ADD R0, R1, R2”.
code_template 是汇编指令的模板, 例如 “ADD %[result], %[input_i], %[input_j]”. 如果你列出了code_template,而不是code,那么你必须在指定optional input_operand_list 和clobbered_register_list之前,先指定output_operand_list。
output_operand_list是一个输出操作数列表, 用逗号分隔。
举例:

#include <stdio.h>
int add(int i, int j)
{
int res = 0;
__asm ("ADD %[result], %[input_i], %[input_j]"
: [result] "=r" (res)
: [input_i] "r" (i), [input_j] "r" (j)
);
return res;
}
int main(void)
{
int a = 1;
int b = 2;
int c = 0;
c = add(a,b);
printf("Result of %d + %d = %d\n", a, b, c);
}

加载8到r0寄存区

void sum (void)
{
__asm (
	"mov r0, #8"
);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值