注:本程序在ARM Developer Suite v1.2下調(diào)試通過。//---------------------------------------------------------------------------
本文引用地址:http://m.butianyuan.cn/article/201611/319212.htm// main.c
//---------------------------------------------------------------------------
#include
#include
#include
extern void start(int num,int *arr);
void sort(int num, int *arr)//C語言冒泡排序
{
int i,j,temp;
for(j=0;j<=num-1;j++)
{
for (i=0;iif (arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
int main(void)
{
int num = 10;
int arr[10],i;
srand(time(0));
while(1)
{
printf("before sort result:n");
for (i=0;i<10;i++){
arr[i] = rand() % 100;
printf("%dt",arr[i]);
}
printf("n");
start(num,arr);
//sort(num, arr);
printf("after sort result:n");
for (i = 0;i<10;i++){
printf("%dt",arr[i]);
}
printf("n");
printf("n");
}
}
//---------------------------------------------------------------------------
// 匯編冒泡排序算法
// sort.s
// 除了start、stag1、stag2可以頂頭,其他匯編程序代碼前均有一個tab鍵
//---------------------------------------------------------------------------
area sort,code,readonly
code32
export start ; 向外聲明方法start
start
mov r7,r1
stag1
sub r0,r0,#1
cmp r0,#0
movle pc,r14
mov r2,#0
mov r1,r7
stag2
ldr r3,[r1]
ldr r4,[r1,#4]!
cmp r3,r4
strgt r3,[r1]
strgt r4,[r1,#-4]
add r2,r2,#1
cmp r2,r0
beq stag1
b stag2
end
評論