#132815 - DiscoStew - Fri Jun 29, 2007 8:45 pm
I've read through a few posts concerning this type of problem, and what is known is that reading from a non-halfword aligned address would result in unpredictable values. However, what I am trying to do here is read a 4-byte value from an address which would be on a 2-byte aligned address, but not a 4-byte aligned address.
For some reason, in one part of a binary file I am reading from, I'm reading a 4-byte value from a 2-byte aligned address with no problems, but at another point in the binary file, the same kind of read is being done, but I'm getting an odd result. Let me give a more descriptive explanation...
Say I have data in my binary file as such (starting at 0x02000000) in little endian...
00 00 01 00 02 00 08 00 00 00 01 00 01......
So, I'm reading a 2-byte value at 0x02000002, which would net me 0x0001, correct? A 4-byte value at that same address, however, give me 0x00000001, and not 0x00020001. along with that, if I read 4-bytes from 0x02000006, I'm getting 0x00020008 instead of just 0x00000008. It's almost like when reading 4 bytes from a 2-byte aligned address, it reads 2 bytes from the address given, then reads the previous 2 bytes.
Is this correct, and is this how it is supposed to work? It's kind of odd that I get a problem in one part of the binary, but not in the other. But, if it is supposed to read this way, should I just read 2 bytes at a time manually, and put them together if I need a 4-byte value?
_________________
DS - It's all about DiscoStew
For some reason, in one part of a binary file I am reading from, I'm reading a 4-byte value from a 2-byte aligned address with no problems, but at another point in the binary file, the same kind of read is being done, but I'm getting an odd result. Let me give a more descriptive explanation...
Say I have data in my binary file as such (starting at 0x02000000) in little endian...
00 00 01 00 02 00 08 00 00 00 01 00 01......
So, I'm reading a 2-byte value at 0x02000002, which would net me 0x0001, correct? A 4-byte value at that same address, however, give me 0x00000001, and not 0x00020001. along with that, if I read 4-bytes from 0x02000006, I'm getting 0x00020008 instead of just 0x00000008. It's almost like when reading 4 bytes from a 2-byte aligned address, it reads 2 bytes from the address given, then reads the previous 2 bytes.
Is this correct, and is this how it is supposed to work? It's kind of odd that I get a problem in one part of the binary, but not in the other. But, if it is supposed to read this way, should I just read 2 bytes at a time manually, and put them together if I need a 4-byte value?
_________________
DS - It's all about DiscoStew