* device/lib/pic/Makefile.rules,
[fw/sdcc] / support / regression / tests / regtrack.c
1 /*
2    regtrack.c - testing register tracking
3 */
4
5 #include <testfwk.h>
6 #include <string.h>
7
8 #ifndef SDCC_mcs51
9 #  define __xdata
10 #  define __pdata
11 #  define __code
12 #endif
13
14 volatile unsigned char __xdata t;
15
16 __pdata      unsigned char ta[]={0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};
17 __code const unsigned char tb[]={0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};
18
19 static void 
20 foo(unsigned char which)
21 {
22   unsigned char i,k; // should be allocated to registers
23
24   k = 2;
25   do
26   {
27       t = 0xab;
28       i = 2;
29       do
30       {
31         switch( which )
32         {
33           case 1: k = 1;
34                   t = 1;    // mov
35                   break;
36           case 2: t = 0x01; 
37                   t = 0x02; // inc
38                   break;
39           case 3: t = 0x05;
40                   t = 0x04;
41                   t = 0x03; // dec
42                   break;
43           case 4: t = ~0x04;
44                   t = 0x04; // cpl
45                   break;
46           case 5: t = 0x05<<1;
47                   t = 0x05; // rr
48                   break;
49           case 6: t = 0x06>>1;
50                   t = 0x06; // rl
51                   break;
52           case 7: t = 0x70;
53                   t = 0x07; // swap
54                   break;
55           case 0x08: 
56                   t = 0x0a;
57                   k = 0x02;
58                   t = 0x08; // xrl
59                   break;
60           case 0x09: 
61                   t = 0x0f;
62                   k = 0xf9;
63                   t = 0x09; // anl
64                   break;
65           case 0x0a: 
66                   t = 0x08;
67                   k = 0x02;
68                   t = 0x0a; // orl
69                   break;
70           case 0x0b: 
71                   t = 0x0b*7;
72                   k = 7;
73                   t = t/7;  // div
74                   break;
75           case 0x0c: 
76                   t = 4;
77                   k = 3;
78                   t = t*3;  // mul
79                   break;
80         }
81       } while(--i);
82   }while(--k);
83
84 }
85
86
87
88
89 void testRegTrack(void)
90 {
91   ASSERT(0==(char)memcmp(ta, tb, sizeof tb));
92
93   foo(1); ASSERT(t==1);
94   foo(2); ASSERT(t==2);
95   foo(3); ASSERT(t==3);
96   foo(4); ASSERT(t==4);
97 #if 1  
98   /* various checks for equality */
99   foo(5); ASSERT(!(t^5));
100   foo(6); ASSERT(0==(t^6));
101   foo(7); ASSERT(!(t-7));
102   foo(8); ASSERT(0==(t-8));
103   foo(9); ASSERT(0==((unsigned char)(t+(0x100-9))));
104   foo(10); ASSERT(!((unsigned char)(t+(0x100-10))));
105   foo(11); ASSERT(t>=11 && t<=11);
106   foo(12); ASSERT(t>11 && t<13);
107 #else  
108   foo(5); ASSERT(t==5);
109   foo(6); ASSERT(t==6);
110   foo(7); ASSERT(t==7);
111   foo(8); ASSERT(t==8);
112   foo(9); ASSERT(t==9);
113   foo(10); ASSERT(t==10);
114   foo(11); ASSERT(t==11);
115   foo(12); ASSERT(t==12);
116 #endif
117 }
118