OpenCores
URL https://opencores.org/ocsvn/mips789/mips789/trunk

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [bench/] [sort/] [sort.c] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
#include "..\..\clib\dvc_lib.h"
15
#include "..\..\clib\stringlib.h"
16
 
17
#define SORT_U16
18
 
19
 
20
#ifdef SORT_U8
21
#define DATA_TYPE   unsigned char
22
#define DATA_MAX 0xff
23
#else
24
#ifdef SORT_U16
25
#define DATA_TYPE  unsigned  short
26
#define DATA_MAX 0xffff
27
#else
28
#define DATA_TYPE   unsigned int
29
#define DATA_MAX 0xffffffff
30
#endif
31
#endif
32
void sort(DATA_TYPE*a,int num)
33
{
34
    int i,j ;
35
 
36
    DATA_TYPE tmp ;
37
 
38
    for(i=0;i<num;i++)
39
    {
40
        for(j=i+1;j<num;j++)
41
        {
42
            if(a[i]<a[j])
43
            {
44
                tmp=a[i];
45
                a[i]=a[j];
46
                a[j]=tmp ;
47
            }
48
        }
49
    }
50
}
51
 
52
DATA_TYPE array[16]={123,234,122,111,222,122,332,111,11,99,11,12,43,23,43,45};
53
 
54
 
55
    /*
56
void initial_array(DATA_TYPE*a,int num)
57
{
58
    int i ;
59
    for(i=0;i<num;++i)
60
    array[i]=DATA_MAX-array[i];
61
} */
62
char str[100];
63
void main2()
64
{
65
    int i ;
66
//initial_array(array,16);
67
    for(;;)
68
    {
69
 
70
        sort(array,16);
71
        for(i=0;i<16;++i)
72
        {
73
            sprintf(str,"  %x",array[i]);
74
            uart0_putstr(str);
75
        }
76
        uart0_putstr(" \n");
77
    }
78
}
79
 
80
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.