1 /*
2    regtrack.c - testing register tracking
3 */
4 
5 #include <testfwk.h>
6 #include <string.h>
7 
8 volatile unsigned char __xdata t;
9 
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};
12 
13 static void
foo(unsigned char which)14 foo (unsigned char which)
15 {
16   unsigned char i, k;  // should be allocated to registers
17   volatile unsigned char m = 1;
18 
19   k = 2;
20   do
21     {
22       t = 0xab;
23       i = 2;
24       do
25         {
26           switch( which )
27             {
28             case 1:
29               k = 1;
30               t = 1;    // mov
31               break;
32 
33             case 2:
34               t = 0x01;
35               t = 0x02; // inc
36               break;
37 
38             case 3:
39               t = 0x05;
40               t = 0x04;
41               t = 0x03; // dec
42               break;
43 
44             case 4:
45               t = ~0x04;
46               t = 0x04; // cpl
47               break;
48 
49             case 5:
50               t = 0x05 << 1;
51               t = 0x05; // rr
52               break;
53 
54             case 6:
55               t = 0x06 >> 1;
56               t = 0x06; // rl
57               break;
58 
59             case 7:
60               t = 0x70;
61               t = 0x07; // swap
62               break;
63 
64             case 0x08:
65               t = 0x0a;
66               k = 0x02;
67               t = 0x08; // xrl
68               break;
69 
70             case 0x09:
71               t = 0x0f;
72               k = 0xf9;
73               t = 0x09; // anl
74               break;
75 
76             case 0x0a:
77               t = 0x08;
78               k = 0x02;
79               t = 0x0a; // orl
80               break;
81 
82             case 0x0b:
83               t = 0x0b * 7;
84               k = 7;
85               t = t/7;  // div
86               break;
87 
88             case 0x0c:
89               t = 4;
90               k = 3;
91               t = t * 3;  // mul
92               break;
93             }
94         }
95       while (--i);
96 
97       if (!i)
98         k = m; // prepare to exit outer loop
99     }
100   while (--k);
101 
102 }
103 
104 
105 
106 
107 void
testRegTrack(void)108 testRegTrack (void)
109 {
110   ASSERT (0 == (char)memcmp (ta, tb, sizeof tb));
111 
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
136 }
137 
138