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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [verif/] [sw/] [C/] [sort.c] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 dinesha
/*
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 <8051.h>
12
 
13
 
14
char cErrCnt;
15
 
16
/*---------------------------------------------------------------------------*/
17
 
18
void sort(unsigned char* buf, unsigned char n) {
19
 
20
    unsigned char i, j, t;
21
 
22
    for(i=0; i<n; i++) {
23
 
24
        for(j=i; j<n; j++) {
25
 
26
            if( buf[i] > buf[j] ) {
27
 
28
                t = buf[i];
29
                buf[i] = buf[j];
30
                buf[j] = t;
31
            }
32
        }
33
    }
34
    P0 = 0;
35
}
36
 
37
/*---------------------------------------------------------------------------*/
38
 
39
void print(unsigned char* buf, unsigned char *exp_buf,unsigned char n) {
40
 
41
    char i;
42
 
43
    for(i=0; i<n; i++) {
44
        P0 = buf[i];
45
        P1 = exp_buf[i];
46
        if(buf[i] != exp_buf[i]) {
47
           cErrCnt++;
48
        }
49
    }
50
 
51
    if(cErrCnt !=0) {
52
        P2 = 0x55; // Test Fail
53
        P3 = cErrCnt;
54
 
55
    } else {
56
       P2 = 0xAA; // Test PASS
57
       P3 = 0xAA; // Test PASS
58
    }
59
 
60
 
61
}
62
 
63
/*---------------------------------------------------------------------------*/
64
 
65
void main() {
66
 
67
    unsigned char buf[]      = { 19, 18, 14, 15, 16, 17, 13, 11, 12, 10 };
68
    // Sorted expected buffer
69
    unsigned char exp_buf[]  = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
70
    cErrCnt = 0;
71
 
72
    sort(buf, 10);
73
    print(buf, exp_buf,10);
74
    while(1);
75
}

powered by: WebSVN 2.1.0

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