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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [twotasks-2/] [task1/] [task1.c] - Blame information for rev 27

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

Line No. Rev Author Line
1 18 hellwig
/*
2
 * task1.c -- a simple task
3
 */
4
 
5
 
6
#include "putchar.h"
7
#include "stdarg.h"
8
 
9
 
10
/**************************************************************/
11
 
12
 
13
void puts(char *s) {
14
  char c;
15
 
16
  while ((c = *s++) != '\0') {
17
    putchar(c);
18
  }
19
}
20
 
21
 
22
void printn(int n) {
23
  int a;
24
 
25
  if (n < 0) {
26
    putchar('-');
27
    n = -n;
28
  }
29
  a = n / 10;
30
  if (a != 0) {
31
    printn(a);
32
  }
33
  putchar(n % 10 + '0');
34
}
35
 
36
 
37
void printu(unsigned int n, unsigned int b) {
38
  unsigned int a;
39
 
40
  a = n / b;
41
  if (a != 0) {
42
    printu(a, b);
43
  }
44
  putchar("0123456789ABCDEF"[n % b]);
45
}
46
 
47
 
48
void printf(char *fmt, ...) {
49
  va_list ap;
50
  char c;
51
  int n;
52
  unsigned int u;
53
  char *s;
54
 
55
  va_start(ap, fmt);
56
  while (1) {
57
    while ((c = *fmt++) != '%') {
58
      if (c == '\0') {
59
        va_end(ap);
60
        return;
61
      }
62
      putchar(c);
63
    }
64
    c = *fmt++;
65
    if (c == 'd') {
66
      n = va_arg(ap, int);
67
      printn(n);
68
    } else
69
    if (c == 'u' || c == 'o' || c == 'x') {
70
      u = va_arg(ap, int);
71
      printu(u, c == 'o' ? 8 : (c == 'x' ? 16 : 10));
72
    } else
73
    if (c == 's') {
74
      s = va_arg(ap, char *);
75
      puts(s);
76
    } else {
77
      putchar(c);
78
    }
79
  }
80
}
81
 
82
 
83
/**************************************************************/
84
 
85
 
86
void main(void) {
87
  int i;
88
 
89
  printf("TASK1: executing...\n");
90
  i = 0;
91
  while (1) {
92
    printf("TASK1: %d\n", i);
93
    i++;
94
  }
95
}

powered by: WebSVN 2.1.0

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