Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / absolute.c
1 /** Absolute addressing tests.
2
3     mem: code, xdata
4 */
5 #include <testfwk.h>
6
7 #ifdef SDCC_pic16
8 # define ADDRESS(x) (0x02 ## x)
9 #else
10 # define ADDRESS(x) (0xCA ## x)
11 #endif
12
13 typedef struct
14 {
15         int a,b;
16 } TestStruct;
17
18 {mem} volatile at(ADDRESS(BC)) TestStruct TestVar = {0,0};
19 {mem} at(ADDRESS(B7)) char u;
20 {mem} at(ADDRESS(B7)) char x = 'x';
21 {mem} at(ADDRESS(B9)) char y = 'y';
22 {mem} at(ADDRESS(B0)) int  k = 0x1234;
23
24 char z = 'z';
25
26 void
27 testAbsolute(void)
28 {
29 #if defined(SDCC_mcs51) || defined(SDCC_ds390) || defined(SDCC_hc08)
30   static {mem} at(ADDRESS(B6)) char s = 's';
31   char {mem} *pC = (char {mem} *)(ADDRESS(B0));
32   int  {mem} *pI = (int  {mem} *)(ADDRESS(B0));
33
34   ASSERT(u == 'x');
35   ASSERT(pC[7] == 'x');
36   ASSERT(pC[9] == 'y');
37   ASSERT(pC[6] == 's');
38   ASSERT(pI[0] == 0x1234);
39 #endif
40 }
41
42 #if defined(SDCC_mcs51) || defined(SDCC_ds390)
43 volatile data at(0x20) unsigned char Byte0 = 0x00;
44 volatile data at(0x22) unsigned char Byte1 = 0x00;
45 volatile bit Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8;
46 #endif
47
48 void
49 testAbsBdata(void)
50 {
51 #if defined(SDCC_mcs51) || defined(SDCC_ds390)
52   Bit0 = 1;
53   ASSERT(Byte0 == 0x00);
54   Byte0 = 0xFF;
55   Bit0 = 0;
56   ASSERT(Byte0 == 0xFF);
57 #endif
58 }