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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [tools/] [count.c] - Blame information for rev 42

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

Line No. Rev Author Line
1 35 rhoads
/*count.c*/
2
void putchar(int);
3
int puts(const char*);
4
 
5
char *name[]={
6
   "","one","two","three","four","five","six","seven","eight","nine",
7
   "ten","eleven","twelve","thirteen","fourteen","fifteen",
8
      "sixteen","seventeen","eighteen","nineteen",
9
   "","ten","twenty","thirty","forty","fifty","sixty","seventy",
10
      "eighty","ninety"
11
};
12
 
13 42 rhoads
#ifndef MLITE
14 35 rhoads
int puts(const char *ptr)
15
{
16
   while(*ptr) {
17
      putchar(*ptr++);
18
   }
19
   return 0;
20
}
21
#endif
22
 
23
char *itoa(unsigned long num)
24
{
25
   static char buf[12];
26
   int i;
27
   buf[10]=0;
28
   for(i=9;i>=0;--i) {
29
      buf[i]=(char)((num%10)+'0');
30
      num/=10;
31
   }
32
   return buf;
33
}
34
 
35
#if 0
36
char *xtoa(unsigned long num)
37
{
38
   static char buf[12];
39
   int i,digit;
40
   buf[8]=0;
41
   for(i=7;i>=0;--i) {
42
      digit=num&0xf;
43
      buf[i]=digit+(digit<10?'0':'A'-10);
44
      num>>=4;
45
   }
46
   return buf;
47
}
48
#endif
49
 
50
void number_text(unsigned long number)
51
{
52
   int digit;
53
   puts(itoa(number));
54
   puts(": ");
55
   if(number>=1000000000) {
56
      digit=number/1000000000;
57
      puts(name[digit]);
58
      puts(" billion ");
59
      number%=1000000000;
60
   }
61
   if(number>=100000000) {
62
      digit=number/100000000;
63
      puts(name[digit]);
64
      puts(" hundred ");
65
      number%=100000000;
66
      if(number<1000000) {
67
         puts("million ");
68
      }
69
   }
70
   if(number>=20000000) {
71
      digit=number/10000000;
72
      puts(name[digit+20]);
73
      putchar(' ');
74
      number%=10000000;
75
      if(number<1000000) {
76
         puts("million ");
77
      }
78
   }
79
   if(number>=1000000) {
80
      digit=number/1000000;
81
      puts(name[digit]);
82
      puts(" million ");
83
      number%=1000000;
84
   }
85
   if(number>=100000) {
86
      digit=number/100000;
87
      puts(name[digit]);
88
      puts(" hundred ");
89
      number%=100000;
90
      if(number<1000) {
91
         puts("thousand ");
92
      }
93
   }
94
   if(number>=20000) {
95
      digit=number/10000;
96
      puts(name[digit+20]);
97
      putchar(' ');
98
      number%=10000;
99
      if(number<1000) {
100
         puts("thousand ");
101
      }
102
   }
103
   if(number>=1000) {
104
      digit=number/1000;
105
      puts(name[digit]);
106
      puts(" thousand ");
107
      number%=1000;
108
   }
109
   if(number>=100) {
110
      digit=number/100;
111
      puts(name[digit]);
112
      puts(" hundred ");
113
      number%=100;
114
   }
115
   if(number>=20) {
116
      digit=number/10;
117
      puts(name[digit+20]);
118
      putchar(' ');
119
      number%=10;
120
   }
121
   puts(name[number]);
122
   putchar('\n');
123
}
124
 
125
void main()
126
{
127
   unsigned long number,i;
128
#if 1
129
   puts("Mult by 3\n");
130
   number=3;
131
   for(i=0;i<100;++i) {
132
      number_text(number);
133
      number*=3;
134
   }
135
#else
136
   for(number=1;number<1000000;++number) {
137
      number_text(number);
138
   }
139
#endif
140
}
141
 

powered by: WebSVN 2.1.0

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