Regression test for #1596270, #1736867
[fw/sdcc] / support / regression / tests / absolute.c
1 /** Absolute addressing tests.
2
3     mem: code, xdata
4 */
5 #include <testfwk.h>
6
7 typedef struct
8 {
9         int a,b;
10 } TestStruct;
11
12 {mem} volatile at(0xCABC) TestStruct TestVar = {0,0};
13 {mem} at(0xCAB7) char u;
14 {mem} at(0xCAB7) char x = 'x';
15 {mem} at(0xCAB9) char y = 'y';
16 {mem} at(0xCAB0) int  k = 0x1234;
17
18 char z = 'z';
19
20 void
21 testAbsolute(void)
22 {
23 #if defined(SDCC_mcs51) || defined(SDCC_ds390) || defined(SDCC_hc08)
24   static {mem} at(0xCAB6) char s = 's';
25   char {mem} *pC = (char {mem} *)(0xCAB0);
26   int  {mem} *pI = (int  {mem} *)(0xCAB0);
27
28   ASSERT(u == 'x');
29   ASSERT(pC[7] == 'x');
30   ASSERT(pC[9] == 'y');
31   ASSERT(pC[6] == 's');
32   ASSERT(pI[0] == 0x1234);
33 #endif
34 }
35
36 #if defined(SDCC_mcs51) || defined(SDCC_ds390)
37 volatile data at(0x20) unsigned char Byte0 = 0x00;
38 volatile data at(0x22) unsigned char Byte1 = 0x00;
39 volatile bit Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8;
40 #endif
41
42 void
43 testAbsBdata(void)
44 {
45 #if defined(SDCC_mcs51) || defined(SDCC_ds390)
46   Bit0 = 1;
47   ASSERT(Byte0 == 0x00);
48   Byte0 = 0xFF;
49   Bit0 = 0;
50   ASSERT(Byte0 == 0xFF);
51 #endif
52 }