资源描述:
《ARM内嵌汇编示例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、ARM内嵌汇编示例说明:所有的文件必须使用arm-linux-gcc编译,在开发板上运行,Makefile文件内容为:CC=arm-linux-gcc01in_out.c#includeintmain(intargc,char**argv){intin=100;intout;__asm____volatile__("movr0,%1""mov%0,r0":"=r"(out):"r"(in):"r0");printf("out=%d",out);return0;}02in_out.c#includeintma
2、in(intargc,char**argv){intin=100;intout;__asm____volatile__("movr0,%[in]"//in作为标号使用,不再用%n表示"mov%[out],r0":[out]"=r"(out):[in]"r"(in):"r0");printf("out=%d",out);return0;}03in_out.c#includeintmain(intargc,char**argv){intin_out=30;intin=100;intout;__asm____volatile__(
3、"movr0,%1""mov%0,r0""movr0,%2""mov%1,r0":"=&r"(out),"+r"(in_out)//有和没有&大不相同:"r"(in):"r0");printf("out=%d",out);printf("in_out=%d",in_out);return0;}04in_out.c#includeintmain(intargc,char**argv){intin1=100,in2=200,in3=10;intout1,out2,out3;__asm____volatile__("m
4、ovr0,%3""movr1,%4""movr2,%5""mov%0,r0""mov%1,r1""mov%2,r2":"=&r"(out1),"=&r"(out2),"=&r"(out3):"r"(in1),"r"(in2),"r"(in3):"r0");return0;}05add.c#includeintmain(intargc,char**argv){intout;#if0__asm____volatile__("movr0,#20""movr1,#30"//"addr0,r1""addr0,r
5、0,r1""mov%0,r0":"=r"(out)::"r0");#endifintout1;__asm____volatile__("movr0,#1""mvnr1,#0"//取反放到r1"addr0,r0,r1""mov%0,r0""movr0,#2""movr1,#3""adcr0,r0,r1"//r0为6,上边进位了"mov%1,r0":"=&r"(out),"=&r"(out1)::"r0","r1");printf("out=%d",out);printf("out1=%d",out1);ret
6、urn0;}06sub.c#includeintmain(intargc,char**argv){intout;#if0__asm____volatile__("movr0,#20""movr1,#5""subr0,r0,r1""mov%0,r0":"=r"(out)::"r0");#endifintout1;__asm____volatile__("movr0,#0""movr1,#1""subsr0,r0,r1"//指令加S会影响CPSR"mov%0,r0""movr0,#10""movr1,#5
7、""sbcr0,r0,r1""mov%1,r0":"=&r"(out),"=&r"(out1)::"r0","r1");printf("out=%x",out);printf("out1=%d",out1);return0;}07mul.c#includeintmain(intargc,char**argv){intout;__asm____volatile__("movr0,#10""movr1,#20""mulr2,r1,r0""mov%0,r2":"=r"(out)::"r0");printf(
8、"out=%d",out);return0;}08cmp.c//lt,gt,