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

Subversion Repositories 8051

[/] [8051/] [tags/] [rel0/] [asm/] [sort.c] - Blame information for rev 186

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 simont
/*
2
 * Copyright (c) 1999-2001 Tony Givargis.  Permission to copy is granted
3
 * provided that this header remains intact.  This software is provided
4
 * with no warranties.
5
 *
6
 * Version : 2.9
7
 */
8
 
9
/*---------------------------------------------------------------------------*/
10
 
11
#include <reg51.h>
12
 
13
/*---------------------------------------------------------------------------*/
14
 
15
void sort(unsigned char* buf, unsigned char n) {
16
 
17
    unsigned char i, j, t;
18
 
19
    for(i=0; i<n; i++) {
20
 
21
        for(j=i; j<n; j++) {
22
 
23
            if( buf[i] > buf[j] ) {
24
 
25
                t = buf[i];
26
                buf[i] = buf[j];
27
                buf[j] = t;
28
            }
29
        }
30
    }
31
    P0 = 0;
32
}
33
 
34
/*---------------------------------------------------------------------------*/
35
 
36
void print(unsigned char* buf, unsigned char n) {
37
 
38
    char i;
39
 
40
    for(i=0; i<n; i++) {
41
 
42
        P0 = buf[i];
43
    }
44
}
45
 
46
/*---------------------------------------------------------------------------*/
47
 
48
void main() {
49
 
50
    unsigned char buf[] = { 19, 18, 17, 16, 15, 14, 13, 12, 11, 10 };
51
 
52
    sort(buf, 10);
53
    print(buf, 10);
54
    while(1);
55
}

powered by: WebSVN 2.1.0

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