I am using an EDK supplied compiler to compile my code for PPC405 on a Virtex-II Pro target device.
I try to write a 64-bit data into int RAM:
eg : *(double *)0x0 = 0x1122334455667788;
When I see the disassembly of the code, the stw data is not as I programmed; it is 0x43B1223344556678 instead of 0x1122334455667788 in assembly language.
Why does this occur?
Most likely you are trying to store an 8 bytes value to memory. Instead of using double, you should use "volatile unsigned long long" or "volatile Xuint64":
*(volatile unsigned long long *) 0x30 = 0x1122334455667788;
The "volatile" guarantees that the compiler does not optimize the assignment away if optimizations are turned on.
In the example below, the compiler is performing correctly. It takes an unsigned long constant, converts it to double precision floating point in IEEE format, and stores it to address location 0x30. You can verify the compiler is performing correctly by changing the program a bit and printing the value (you can also compile and run the program on a Windows/Linux/Solaris machine):
a = 0x1122334455667788ULL;
printf("%lld, %f\n", 0x1122334455667788, a);
Running this prints:
This is the correct decimal value for the hexadecimal 0x1122334455667788.
When you look at the disassembly of this program, 0x43b1223344556678 is the double precision IEEE representation of the same value.