J
Jay Azurin
Hello,
I'm trying to create a memory dump parser tool for which I plan to use
existing header files that contain structures of registers. My plan
is to use a union and include the structures in the header files plus
a 'dump' variable where I would store the memory dump. A simplified
version of this would look something like this:
union
{
struct
{
unsigned short first1; //first half of first word
unsigned short second1; //sencond half of first word
unsigned long whole; //second word
}words;
unsigned long dump[2]; //two words
}words_union;
main()
{
words_union.dump[0] = 0x1BADC0DE;
words_union.dump[1] = 0x1BADC0DE;
return 0;
}
Where the struct 'words' represents a register memory map, and dump[]
my dump place holder.
After running main() what I'm seeing in memory is that first1 =
0xC0DE, second1 = 0x1BAD, and whole = 0x1BADCODE.
My expectaion (and wish) is that first1 = 0x1BAD, and second1 =
0xCODE. But apparently these two half words are reversed in memory.
My feeling is that this has to do with endianess, but I'm not sure,
could anyone give a clue on how to store the half words in memory
correctly?
Thanks in advance.
I'm trying to create a memory dump parser tool for which I plan to use
existing header files that contain structures of registers. My plan
is to use a union and include the structures in the header files plus
a 'dump' variable where I would store the memory dump. A simplified
version of this would look something like this:
union
{
struct
{
unsigned short first1; //first half of first word
unsigned short second1; //sencond half of first word
unsigned long whole; //second word
}words;
unsigned long dump[2]; //two words
}words_union;
main()
{
words_union.dump[0] = 0x1BADC0DE;
words_union.dump[1] = 0x1BADC0DE;
return 0;
}
Where the struct 'words' represents a register memory map, and dump[]
my dump place holder.
After running main() what I'm seeing in memory is that first1 =
0xC0DE, second1 = 0x1BAD, and whole = 0x1BADCODE.
My expectaion (and wish) is that first1 = 0x1BAD, and second1 =
0xCODE. But apparently these two half words are reversed in memory.
My feeling is that this has to do with endianess, but I'm not sure,
could anyone give a clue on how to store the half words in memory
correctly?
Thanks in advance.