藏书阁 史将 特技
背景 三国演义 PC版
首页 -> 精彩文章 -> 文章
RE:嵌入式作业一排序
作者拉格浪日
标签编程
阅读次数:30
i really do not know why the array is lost in the function select?
ok in codewarrior
-----------------------------------------------------sort2.c
#include
#include
extern void select(int *src,int number);

int main() {
int i=0;
int num=0;
int *array=NULL;
int *array2[1];


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);
}
array2[0]=array;
printf("please enter the elements:\n");
for(i = 0; i printf("\n%d:\t", i);
scanf("%d", array+i);
}
select(array,num);
printf("=========================\nthe result is:\n");
for(i = 0; i printf("%d:\t%d\n", i, *(array2[0]+i));
}

return 0;

}
------------------------------ sort_asm.s
  AREA Scopy,CODE,READONLY
  EXPORT select
select
    SUBS R1,R1,#1
loop MOV R7,R1
   MOV R4,R0
loop2 LDR R5,[R4]
  LDR R6,[R4,#4]!
CMP R5,R6
BLS skip
STR R5,[R4]
STR R6,[R4,#-4]
skip  SUBS R1,R1,#1
BNE loop2
MOV R1,R7
SUBS R1,R1,#1
BNE loop
    END


浙ICP备06020153号-1