Below is my code. Please note that I am not running this code on a normal machine, but on an architecture simulator (gem5).
#include <stdio.h>
int main()
{
int *p;
int x;
p = &x;
p[0] = 3;
// *(0xffff) = 6;
return 0;
}
If I uncomment the line, I get a compiler error (which is expected) "indirection requires pointer operand". Since I am not running it on an actual machine, but on a simulator, I have control over how the hardware behaves, and the address space. I want to store value 6 in address 0xffff. One way to do this is:
int *p;
p = (int *)0xffff;
p[0] = 6;
Please note that this will not result in a segmentation fault for me, because I am running it on a simulator, and I control the address space. But, this is an inefficient way, because every time variable 'p' should be accessed, get 0xffff, and then store 6. Accessing variable 'p' even if declared as register, will take 1 cycle which is costly for me in the long run. Since I know 'p' will always have 0xffff, can't I write something like
*(0xffff) = 3;
How do I allow the compiler to generate this code? Any pointers will be of help.