1 // Signed comparisons of the form: (variable>=LIT)
3 // This regression test exercises all of the boundary
4 // conditions in literal less than comparisons. There
5 // are numerous opportunities to optimize these comparison
6 // and each one has an astonishing capability of failing
7 // a boundary condition.
9 unsigned char success = 0;
10 unsigned char failures = 0;
11 unsigned char dummy = 0;
12 unsigned char result = 0;
17 unsigned char uchar0 = 0;
18 unsigned char uchar1 = 0;
19 signed char char0 = 0;
20 signed char char1 = 0;
24 /* copied from 16f877.inc file supplied with gpasm */
26 #define _CP_ALL 0x0FCF
27 #define _CP_HALF 0x1FDF
28 #define _CP_UPPER_256 0x2FEF
29 #define _CP_OFF 0x3FFF
30 #define _DEBUG_ON 0x37FF
31 #define _DEBUG_OFF 0x3FFF
32 #define _WRT_ENABLE_ON 0x3FFF
33 #define _WRT_ENABLE_OFF 0x3DFF
34 #define _CPD_ON 0x3EFF
35 #define _CPD_OFF 0x3FFF
36 #define _LVP_ON 0x3FFF
37 #define _LVP_OFF 0x3F7F
38 #define _BODEN_ON 0x3FFF
39 #define _BODEN_OFF 0x3FBF
40 #define _PWRTE_OFF 0x3FFF
41 #define _PWRTE_ON 0x3FF7
42 #define _WDT_ON 0x3FFF
43 #define _WDT_OFF 0x3FFB
44 #define _LP_OSC 0x3FFC
45 #define _XT_OSC 0x3FFD
46 #define _HS_OSC 0x3FFE
47 #define _RC_OSC 0x3FFF
49 /* *** NOTE *** This particular test takes quite a while to run
50 * ~ 10,000,000 instruction cycles. (2.5 seconds on a 20Mhz PIC).
51 * The WDT will reset the CPU if it's enabled. So disable it...
54 typedef unsigned int word;
56 word at 0x2007 CONFIG = _WDT_OFF & _PWRTE_ON;
65 void c_char_gte_lit1(unsigned char expected_result)
88 if(result != expected_result)
93 void char_compare(void)
96 c_char_gte_lit1(0x3f);
99 c_char_gte_lit1(0x1f);
102 c_char_gte_lit1(0x0f);
105 c_char_gte_lit1(0x0f);
108 c_char_gte_lit1(0x0f);
111 c_char_gte_lit1(0x07);
114 c_char_gte_lit1(0x03);
117 c_char_gte_lit1(0x01);
120 c_char_gte_lit1(0x01);
123 c_char_gte_lit1(0x01);
126 c_char_gte_lit1(0x01);
129 c_char_gte_lit1(0x00);
132 /* Now test entire range */
134 for(char0=1; char0 != 0x7e; char0++)
135 c_char_gte_lit1(0x0f);
137 for(char0=-0x7f; char0 != -1; char0++)
138 c_char_gte_lit1(0x01);
143 void c_int_gte_lit1(unsigned char expected_result)
172 if(result != expected_result)
178 void int_compare1(void)
181 c_int_gte_lit1(0x00);
184 c_int_gte_lit1(0x01);
187 c_int_gte_lit1(0x03);
190 c_int_gte_lit1(0x03);
193 c_int_gte_lit1(0x03);
196 c_int_gte_lit1(0x07);
199 c_int_gte_lit1(0x0f);
202 c_int_gte_lit1(0x1f);
205 c_int_gte_lit1(0x1f);
208 c_int_gte_lit1(0x1f);
211 c_int_gte_lit1(0x3f);
214 c_int_gte_lit1(0x7f);
217 c_int_gte_lit1(0xff);
220 c_int_gte_lit1(0xff);
222 /* now check contiguous ranges */
224 for(int0 = -0x7fff; int0 != -1; int0++)
225 c_int_gte_lit1(0x00);
227 for(int0 = 1; int0 != 0xff; int0++)
228 c_int_gte_lit1(0x03);
230 for(int0 = 0x201; int0 != 0x7fff; int0++)
231 c_int_gte_lit1(0xff);
236 void c_int_gte_lit2(unsigned char expected_result)
264 if(result != expected_result)
268 void int_compare2(void)
271 c_int_gte_lit2(0x01);
274 c_int_gte_lit2(0x03);
277 c_int_gte_lit2(0x07);
280 c_int_gte_lit2(0x0f);
283 c_int_gte_lit2(0x0f);
286 c_int_gte_lit2(0x0f);
289 c_int_gte_lit2(0x0f);
292 c_int_gte_lit2(0x0f);
295 c_int_gte_lit2(0x1f);
298 c_int_gte_lit2(0x3f);
301 c_int_gte_lit2(0x7f);
304 c_int_gte_lit2(0x7f);
307 c_int_gte_lit2(0xff);
310 c_int_gte_lit2(0xff);
313 c_int_gte_lit2(0xff);
316 c_int_gte_lit2(0xff);
318 /* now check contiguous ranges */
320 for(int0 = -0x7fff; int0 != -0x7f00; int0++)
321 c_int_gte_lit2(0x01);
323 for(int0 = -0x7e00; int0 != -0x101; int0++)
324 c_int_gte_lit2(0x0f);
326 for(int0 = -1; int0 != 0x7fff; int0++)
327 c_int_gte_lit2(0xff);