Steve Tell fixed a nested for-loop bug in the PIC Port
[fw/sdcc] / src / regression / sub2.c
1 #define __16F873
2 #include "p16f873.h"
3 //#include "p16c84.h"
4 // Addition tests
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 /* Some compilers that support bit types do not support bit arithmetic 
11  * (like bitx = bity + bitz;) */
12 #define SUPPORT_BIT_ARITHMETIC 1
13
14 unsigned char success=0;
15 unsigned char failures=0;
16 unsigned char dummy=0;
17
18 #if SUPPORT_BIT_TYPES
19
20 bit bit0 = 0;
21 bit bit1 = 0;
22 bit bit2 = 0;
23 bit bit3 = 0;
24 bit bit4 = 0;
25 bit bit5 = 0;
26 bit bit6 = 0;
27 bit bit7 = 0;
28 bit bit8 = 0;
29 bit bit9 = 0;
30 bit bit10 = 0;
31 bit bit11 = 0;
32
33 #endif
34
35 int int0 = 0;
36 int int1 = 0;
37 char char0 = 0;
38 char char1 = 0;
39 char char2 = 0;
40
41
42 void done()
43 {
44
45   dummy++;
46
47 }
48
49 void sub_int1(void)
50 {
51   if(int0 != 5)
52     failures++;
53
54   if(int1 != 4)
55     failures++;
56
57   int0 = int0 - int1;
58
59   if(int0 != 1)
60     failures++;
61
62   int0 = 4 - int0;
63   if(int0 != 3)
64     failures++;
65
66   int0 = int0 - int1;
67
68   if(int0 != -1)
69     failures++;
70
71   int0 = int0 - 0xff;
72
73   if(int0 != -0x100)
74     failures++;
75
76   int0 = 0xff - int0;
77
78   if(int0 != 0x1ff)
79     failures++;
80
81
82 }
83
84 void sub_char_int(void)
85 {
86
87   int0 = int0 - char0;
88
89   if(int0 != 3)
90     failures++;
91
92   if(int0 < char0)
93     failures++;
94
95   int0 = int0 - char0;
96
97   if(int0 != 1)
98     failures++;
99
100   if(int0 > char0)
101     failures++;
102
103
104   int0 = int0 - char0;
105   if(int0 != -1)
106     failures++;
107
108   if(int0>0)
109     failures++;
110
111 }
112
113 void assign_char2int(void)
114 {
115
116   int0 = char0;
117   if(int0 != 0x7f)
118     failures++;
119
120   int1 = char1;
121   if(int1 != -5)
122     failures++;
123
124 }
125
126
127 void sub_compound_char(void)
128 {
129
130   char0 = char1 - 5;
131   if(char0 != 4)
132     failures++;
133
134   if((char1 - char0 - 5) != 0)
135     failures++;
136
137 }
138
139 void sub_compound_int(void)
140 {
141
142   int0 = int1 - 5;
143   if(int0 != 4)
144     failures++;
145
146   if((int1 - int0 - 5) != 0)
147     failures++;
148
149 }
150
151 void main(void)
152 {
153
154   int0 = 5;
155   int1 = 4;
156
157   sub_int1();
158
159   int0 = 5;
160   int1 = 4;
161   char0 = 2;
162
163   sub_char_int();
164
165   char0 = 0x7f;
166   char1 = -5;
167   assign_char2int();
168
169   char1 = 9;
170   sub_compound_char();
171   
172   int1 = 9;
173   sub_compound_int();
174
175   success = failures;
176   done();
177 }