Watch byte streams in Memory Window more easily.

13 11 2008

Assembly programming! It fascinates me always. I love sending packets of data to hardware, parsing back the replies, etc. You might be using BYTE arrays for doing such stuffs. well, in that case, instead of watch window, memory window is preferable to see the byte stream, because it will be so easy to see the entire message.

For instance, assume that we need to send a packet of data in following format.

Following code snippet generates similar array. Ofcourse in legacy coding style.

// Data packet.
const int DATA_PACKET_LEN = 12;
BYTE DataPacket[DATA_PACKET_LEN] = { 0 };

int Index = 0;

// Add the first DWORD.
DataPacket[Index] = 1;
Index += sizeof( DWORD );

// Add the second WORD.
DataPacket[Index] = 2;
Index += sizeof( WORD );

// Add the third WORD.
DataPacket[Index] = 3;
Index += sizeof( WORD );

// Add the forth DWORD.
DataPacket[Index] = 4;
Index += sizeof( DWORD );

If you watch DataPacket in memory window, it will look like this.
A chunk of bytes. It seems hard to read and interpret values. isn’t it? More over that, in intel machines, the values are stored in LSB format which makes the readability even more worse. well is there any trick which helps to read the format even better.

If you right click in the Memory window, you’ll get the context menu and in that you can select the preferred byte ordering.

Select “Long Hex Format” to group bytes as DWORDs. Well, now you can read the byte stream, as such in the packet format picture. cool! isn’t it?

Yes! i know. You’re thinking about this – the second and third parameter get swapped. Well, its due to the fact that Intel machines follows LSB layout for storing values in memory. This is not perfect solution but it does make life easier and having something is better than nothing! isn’t it? 😉

Targeted Audience – Intermediate.