| 1 | // Betting on GCC aligning this for efficiency.\r |
| 2 | #include <stdio.h>\r |
| 3 | \r |
| 4 | int main()\r |
| 5 | {\r |
| 6 | unsigned short int read_16 = 0xF1F2;\r |
| 7 | unsigned int read_32 = 0xF1F2F3F4;\r |
| 8 | \r |
| 9 | unsigned short int write_16 = 0xF00D;\r |
| 10 | unsigned int write_32 = 0xF00DFEED;\r |
| 11 | // 16bit unsigned reads, we expect 0xF1F2 and 0xF20000F1\r |
| 12 | fprintf(stderr, "%04x %04x\n",\r |
| 13 | *((unsigned short int *)((char *)&read_16)),\r |
| 14 | *((unsigned short int *)((char *)&read_16 + 1)));\r |
| 15 | \r |
| 16 | // 16bit signed reads, we expect 0xFFFFF1F2 and 0xFFFFFFF1\r |
| 17 | fprintf(stderr, "%04x %04x\n",\r |
| 18 | *((short int *)((char *)&read_16)),\r |
| 19 | *((short int *)((char *)&read_16 + 1)));\r |
| 20 | \r |
| 21 | // 32bit reads, we expect 0xF1F2F3F4, 0xF4F1F2F3, 0xF3F4F1F2,\r |
| 22 | // and 0xF2F3F4F1\r |
| 23 | \r |
| 24 | fprintf(stderr, "%08x %08x %08x %08x\n",\r |
| 25 | *((int *)((char *)&read_32)),\r |
| 26 | *((int *)((char *)&read_32 + 1)),\r |
| 27 | *((int *)((char *)&read_32 + 2)),\r |
| 28 | *((int *)((char *)&read_32 + 3)));\r |
| 29 | \r |
| 30 | // 16bit writes, we expect write_16 to remain 0xF00D\r |
| 31 | \r |
| 32 | *((short int *)((char *)&write_16)) = 0xF00D;\r |
| 33 | *((short int *)((char *)&write_16) + 1) = 0xF00D;\r |
| 34 | \r |
| 35 | fprintf(stderr, "%04x\n", write_16);\r |
| 36 | \r |
| 37 | // 32bit writes, we expect write_32 to remain 0xF00DFEED\r |
| 38 | \r |
| 39 | *((int *)((char *)&write_16)) = 0xF00DFEED;\r |
| 40 | *((int *)((char *)&write_16) + 1) = 0xF00DFEED;\r |
| 41 | *((int *)((char *)&write_16) + 2) = 0xF00DFEED;\r |
| 42 | *((int *)((char *)&write_16) + 3) = 0xF00DFEED;\r |
| 43 | \r |
| 44 | fprintf(stderr, "%08x\n", write_32);\r |
| 45 | \r |
| 46 | return 0;\r |
| 47 | }\r |
| 48 | \r |