struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / regtrack.c
blob77aaec374f7a7c9a7e3c38776323eacf3ac2c106
1 /*
2 regtrack.c - testing register tracking
3 */
5 #include <testfwk.h>
6 #include <string.h>
8 volatile unsigned char __xdata t;
10 __pdata unsigned char ta[] = {0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};
11 __code const unsigned char tb[] = {0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};
13 static void
14 foo (unsigned char which)
16 unsigned char i, k; // should be allocated to registers
17 volatile unsigned char m = 1;
19 k = 2;
22 t = 0xab;
23 i = 2;
26 switch( which )
28 case 1:
29 k = 1;
30 t = 1; // mov
31 break;
33 case 2:
34 t = 0x01;
35 t = 0x02; // inc
36 break;
38 case 3:
39 t = 0x05;
40 t = 0x04;
41 t = 0x03; // dec
42 break;
44 case 4:
45 t = ~0x04;
46 t = 0x04; // cpl
47 break;
49 case 5:
50 t = 0x05 << 1;
51 t = 0x05; // rr
52 break;
54 case 6:
55 t = 0x06 >> 1;
56 t = 0x06; // rl
57 break;
59 case 7:
60 t = 0x70;
61 t = 0x07; // swap
62 break;
64 case 0x08:
65 t = 0x0a;
66 k = 0x02;
67 t = 0x08; // xrl
68 break;
70 case 0x09:
71 t = 0x0f;
72 k = 0xf9;
73 t = 0x09; // anl
74 break;
76 case 0x0a:
77 t = 0x08;
78 k = 0x02;
79 t = 0x0a; // orl
80 break;
82 case 0x0b:
83 t = 0x0b * 7;
84 k = 7;
85 t = t/7; // div
86 break;
88 case 0x0c:
89 t = 4;
90 k = 3;
91 t = t * 3; // mul
92 break;
95 while (--i);
97 if (!i)
98 k = m; // prepare to exit outer loop
100 while (--k);
107 void
108 testRegTrack (void)
110 ASSERT (0 == (char)memcmp (ta, tb, sizeof tb));
112 foo (1); ASSERT (t == 1);
113 foo (2); ASSERT (t == 2);
114 foo (3); ASSERT (t == 3);
115 foo (4); ASSERT (t == 4);
116 #if 1
117 /* various checks for equality */
118 foo (5); ASSERT (!(t ^ 5));
119 foo (6); ASSERT (0 == (t ^ 6));
120 foo (7); ASSERT (!(t - 7));
121 foo (8); ASSERT (0 == (t - 8));
122 foo (9); ASSERT (0 == ((unsigned char)(t + (0x100 - 9))));
123 foo (10); ASSERT (!((unsigned char)(t + (0x100 - 10))));
124 foo (11); ASSERT (t >= 11 && t <= 11);
125 foo (12); ASSERT (t > 11 && t < 13);
126 #else
127 foo (5); ASSERT (t == 5);
128 foo (6); ASSERT (t == 6);
129 foo (7); ASSERT (t == 7);
130 foo (8); ASSERT (t == 8);
131 foo (9); ASSERT (t == 9);
132 foo (10); ASSERT (t == 10);
133 foo (11); ASSERT (t == 11);
134 foo (12); ASSERT (t == 12);
135 #endif