Steve Tell fixed a nested for-loop bug in the PIC Port
[fw/sdcc] / src / regression / add2.c
1 #define __16F873
2 #include "p16f873.h"
3
4 // Addition tests - mostly int's
5
6 /* bit types are not ANSI - so provide a way of disabling bit types
7  * if this file is used to test other compilers besides SDCC */
8 #define SUPPORT_BIT_TYPES 1
9
10
11 unsigned char success=0;
12 unsigned char failures=0;
13 unsigned char dummy=0;
14
15
16 unsigned int aint0 = 0;
17 unsigned int aint1 = 0;
18 unsigned int aint2 = 0;
19 unsigned int aint3 = 0;
20 unsigned char achar0 = 0;
21 unsigned char achar1 = 0;
22 unsigned char achar2 = 0;
23 unsigned char achar3 = 0;
24 unsigned char *acharP = 0;
25
26 #if SUPPORT_BIT_TYPES
27
28 bit bit0 = 0;
29 bit bit1 = 0;
30 bit bit2 = 0;
31 bit bit3 = 0;
32 bit bit4 = 0;
33 bit bit5 = 0;
34 bit bit6 = 0;
35 bit bit7 = 0;
36 bit bit8 = 0;
37 bit bit9 = 0;
38 bit bit10 = 0;
39 bit bit11 = 0;
40
41 #endif
42
43
44 void done()
45 {
46
47   dummy++;
48
49 }
50
51 void add_lit2uint(void)
52 {
53
54   aint0 = aint0 + 5;
55
56   if(aint0 != 5)
57     failures++;
58
59   aint0 += 10;
60
61   if(aint0 != 15)
62     failures++;
63
64   aint0 = aint0 +1;  // Should be an increment
65   if(aint0 != 16)
66     failures++;
67
68   for(aint1 = 0; aint1 < 100; aint1++)
69     aint0 += 2;
70
71   if(aint0 != 216)
72     failures++;
73
74 }
75
76 void add_uint2uint (void)
77 {
78
79   aint1 = aint1 + aint0;
80
81   if(aint1 != 16)
82     failures++;
83
84   for(aint2 = 0; aint2<7; aint2++)
85     aint1 += aint0;
86
87   if(aint1 != 128)
88     failures++;
89
90 }
91
92 // assumes
93 //  aint0 = 0
94 //  aint1 = 32
95 //  aint2, aint3 can be anything.
96
97 void add_uint2uint2(void)
98 {
99
100
101   aint0++;
102   aint0 = aint0 + 1;
103   aint0 = aint0 + 2;
104   aint0 = aint0 + 3;
105   if(aint0 != 7)
106     failures++;
107
108   aint1 += aint0;
109   if(aint1 != 0x27)
110     failures++;
111
112   aint2 = aint1 + aint0;
113   if(aint2 != 0x2e)
114     failures++;
115
116   aint3 = aint2 + aint1 + aint0;
117   if(aint3 != 0x5c)
118     failures++;
119
120   aint3 += 0xa0;
121   if(aint3 != 0xfc)
122     failures++;
123
124   aint3 += aint0;
125   if(aint3 != 0x103)
126     failures++;
127
128   aint1 += 0xffc0;
129   if(aint1 != 0xffe7)
130     failures++;
131
132   aint3 = aint2 + aint1 + aint0;
133   if(aint3 != 0x1c)
134     failures++;
135
136
137 }
138
139 #if SUPPORT_BIT_TYPES
140 void add_bits(void)
141 {
142
143   bit1 = bit0;
144
145   bit0 = 1;
146
147   if(bit1 != 0)
148     failures++;
149
150   bit1 = bit1+bit0;
151   if(bit1 != 1)
152     failures++;
153
154   bit2 = bit1+bit3;
155   if(!bit2)
156     failures++;
157
158   bit3 = bit4+bit5+bit6+bit7+bit0;
159   if(!bit3)
160     failures++;
161 }
162 #endif
163
164 /* add_bit2uchar(void) - assumes bit0 = 1, aint0 = 7  */
165
166 void add_bit2uchar(void)
167 {
168
169   achar0 += bit0;
170
171   if(achar0 != 8)
172     failures++;
173
174   if(achar0 == bit0)
175     failures++;
176
177 }
178
179 void add_bit2uint(void)
180 {
181
182   if(aint0 != bit11)
183     failures++;
184
185   aint0 += bit0;
186   if(aint0!=1)
187     failures++;
188
189 }
190
191 /***********************************/
192
193 void addlits(void)
194 {
195   aint0 += 0x0001;
196
197   if(aint0 != 1)
198     failures++;
199
200   aint0 += 0x00;
201
202   if(aint0 != 1)
203     failures++;
204
205   aint0 += 0x00fe;
206   if(aint0 != 0x00ff)
207     failures++;
208
209   aint0 += 0x0001;
210
211   if(aint0 != 0x0100)
212     failures++;
213
214   aint0++;
215   if(aint0 != 0x0101)
216     failures++;
217
218   aint0 += 0x00ff;
219   if(aint0 != 0x0200)
220     failures++;
221
222   aint0 += 0x00a0;
223   if(aint0 != 0x02a0)
224     failures++;
225
226   aint0 += 0x0061;
227   if(aint0 != 0x0301)
228     failures++;
229
230   aint0 += 0x0100;
231   if(aint0 != 0x0401)
232     failures++;
233
234   aint0 += 0x0101;
235   if(aint0 != 0x0502)
236     failures++;
237
238   aint0 += 0x00fd;
239   if(aint0 != 0x05ff)
240     failures++;
241
242   aint0 += 0x0101;
243   if(aint0 != 0x0700)
244     failures++;
245
246   aint0 += 0x01ff;
247   if(aint0 != 0x08ff)
248     failures++;
249
250   aint0 += 0x01ff;
251   if(aint0 != 0x0afe)
252     failures++;
253
254   aint0 += 0xff02;
255   if(aint0 != 0x0a00)
256     failures++;
257
258   aint0 += 0xffff;
259   if(aint0 != 0x09ff)
260     failures++;
261
262   aint0 += 0xff01;
263   if(aint0 != 0x0900)
264     failures++;
265
266   aint0 += 0xff00;
267   if(aint0 != 0x0800)
268     failures++;
269
270   aint0 += 0xff01;
271   if(aint0 != 0x0701)
272     failures++;
273
274   aint0 += 0x0300;
275   if(aint0 != 0x0a01)
276     failures++;
277
278   aint0 += 0x03ff;
279   if(aint0 != 0x0e00)
280     failures++;
281
282   aint0 += 0x0301;
283   if(aint0 != 0x1101)
284     failures++;
285
286   aint0 += 0x03fe;
287   if(aint0 != 0x14ff)
288     failures++;
289
290   aint0 += 0x0301;
291   if(aint0 != 0x1800)
292     failures++;
293  
294 }
295
296
297 void main(void)
298 {
299
300   add_lit2uint();
301
302   aint0=16;
303   aint1=0;
304   add_uint2uint();
305
306
307   aint0 = 0;
308   aint1 = 32;
309   aint2 = 0;
310   add_uint2uint2();
311
312 #if SUPPORT_BIT_TYPES
313   add_bits();
314
315   achar0 = 7;
316   add_bit2uchar();
317
318   aint0 = 0;
319   bit0 = 1;
320   add_bit2uint();
321 #endif
322
323   aint0 = 0;
324   addlits();
325
326   success = failures;
327   done();
328 }