Home Articles Books Download FAQs Tips

Debugger: View a range of memory as bytes, words, or dwords

While you are debugging a program, you can use the CPU view to look at the memory space of your process. On BCB4, you can activate the CPU view by choosing the View | Debug Windows | CPU View menu option. You can also use the keyboard shortcut CTRL+ALT+C.

The CPU view consists of four major sections, which are divided into panes via splitter controls. The upper left pane is the code view. It allows you to step through the assembly code of your program as you are debugging. The upper right pane is the register view. It displays the contents of the CPU's registers. The bottom right pane is the stack view. The lower left pane is the memory view. The memory view is the primary focus of this IDE tip. Figure 1 highlights the four panes of the CPU view.

Each pane in the CPU view supports its own, customized popup menu. The popup menu for the memory pane contains two items that allow us to look at memory as bytes, words, or dwords. The first menu item is the Goto Address item. It allows us to choose which part of memory we want to look at. The second menu item is the Display As item. It allows us to view the memory in various formats, including bytes, words, dwords, and floats.

To view a section of memory as dwords, use the Goto Address option to navigate the memory view to the memory that you want to look at, and then select the Display As - dwords option. This will organize the memory as dwords instead of displaying the memory as raw bytes.

At this point, you may be wondering what does it mean to view memory as dwords instead of as bytes. A dword consists of four bytes. On Intel PCs, the lowest byte in memory is the least significant byte in the dword. The highest byte in memory is the most significant byte in the dword. Let's say that you have a dword that is assigned a value 0xFFAA4411, and that the dword resides at memory location 0x1000. The memory will look like this if it is view as raw bytes.

0x00000FF8   00 00 00 00 00 00 00 00
0x00001000   11 44 AA FF 00 00 00 00
0x00001008   00 00 00 00 00 00 00 00

Note that all of the zero's are just added values to make the display look like it would appear if you were looking at the CPU view. The zeroes are not part of the dword.

The dword starts at address 0x00001000. The first value that we see is 0x11, because that's the lowest address in the dword. As we look at the four bytes that make up the dword, we have to mentally flip the bytes around in order to correctly interpret what value is in the variable. This can get confusing. To simplify matters, we can tell the memory view to display the memory in dword mode. In this mode, the CPU view automatically flips the bytes around, so we don't have to flip the bytes in our heads. Here is what the same memory would look like if it was viewed as dwords.

0x00000FF8   00000000 00000000
0x00001000   FFAA4411 00000000
0x00001008   00000000 00000000

When we view the memory as dwords, we don't have to mentally rearrange the bytes. We can just read the value directly. Notice that the gaps between each byte have disappeared. Since a dword consists of four bytes, the CPU displays the memory in groups of four bytes. This helps distinguish between dword mode and byte mode. On more thing to note. The addresses on the left have not changed. They still read 0x00000FF8, 0x00001000, and 0x00001008. But you should realize that the byte at 0x00001000 is not 0xFF, its 0x11. In dword mode, the address means that there is a dword at address 0x00001000.



Copyright © 1997-2000 by Harold Howe.
All rights reserved.