- 论坛徽章:
- 0
|
![]()
文件:arm汇编手册中文版.chm
大小:151KB
下载:
下载
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
在C程序main函数中,接收用户输入任意个整数,然后在main中调用使用ARM汇编编写的函数(在该函数中完成对这些整数的排序功能),然后再在C程序main函数中输出这些排好顺序的整数。
这个要求涉及到了APCS(ARM 过程调用标准),上面的手册中专门介绍了它
main.c
#include stdio.h>
int main()
{
int i=0;
int num=0;
int *array=NULL;
while(num = 0) //输入数组中元素的个数
{
printf("please enter the number of elements:\n");
scanf("%d",&num);
if(num > 0)
{
break;
}
}
if(NULL == (array = (int *)malloc(num*sizeof(int))))
{
printf("malloc failed!\n");
exit(-1);
}
printf("please enter the elements:\n");
for(i = 0; inum; i++) {
printf("\n%d:\t", i);
scanf("%d", array+i);
}
sort(array, num);//调用相应的汇编的函数,注意分析传参过程
printf("The Result is:\n");
for(i = 0; inum; i++) {
printf("%d:\t%d\n", i, *(array+i));
}
return 0;
}
//下面是相应的Sort.s
.section .text;声明为代码段
.globl sort;声明全局变量
sort: ;linux下需要加冒号
mov r2, #0
mov r8, r0
mov r9, r0
loop1:
sub r1, r1, #1
cmp r2, r1
add r1, r1, #1
beq end
mov r6, r2
add r3, r2, #1
loop2:
cmp r3, r1
beq continue1
mov r3, r3, lsl #2
add r8, r8, r3
ldr r5, [r8]
mov r6, r6, lsl #2
add r9, r9, r6
ldr r4, [r9]
cmp r4, r5
bgt exchange
continue2:
sub r8, r8, r3
mov r3, r3, lsr #2
sub r9, r9, r6
mov r6, r6, lsr #2
add r3, r3, #1
b loop2
exchange:
str r4, [r8]
str r5, [r9]
b continue2
continue1:
add r2, r2, #1
b loop1
end:
注意:通过APCS传过来的两个变量,保存在r0和r1,分别代表是数组的首地址和元素的个数
使用Arm交叉编译通过
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/61062/showart_1904902.html |
|