You are on page 1of 6

2.

Familiarity with Debug and Debug32

Background
This lab will introduce you to some of the basic ‘‘tools of the trade’’. The assemblers introduced in this
lab will be used throughout the laboratory course, in the class, and may help you customize your PC
through machine language programming.
DEBUG, supplied by MS-DOS, is a program that traces the 8086 instructions. Using DEBUG, you can
easily enter 8086 machine code program into memory and save it as an executable MS-DOS file (in .COM
format). DEBUG can also be used to test and debug 8086 and 8088 programs. The features include
examining and changing memory and register contents including the CPU register. The programs may also
be single-stepped or run at full speed to a break point.
You will also become familiar with DEBUG32 which is the program supplied in your textbook on the
diskette. It is similar to DEBUG but offers full support for 32-bit instructions and addressing. DEBUG32
includes the 80x86 instructions through the Pentium instructions.

Objectives: Learn to
A. Use DEBUG and DEBUG32 to examine the contents of memory and internal registers.
B. Modify contents of memory, registers, and address space.
C. Write short assembly language sequences using DEBUG32.
D. Single step through a program using the T (trace) function.
E. Assemble and Unassemble code using DEBUG and DEBUG32.

Pre-Lab
Draw a figure like Figure 3.9 in the Uffenbeck text to be completed in lab. Make 3 copies of the map
blank. Read section 4.2 in the Uffenbeck textbook.

Lab
In the first portion of the lab, we will work with DEBUG the program supplied with MS-DOS. The next
portion will utilize DEBUG32 which is the program supplied with your textbook.

A. Loading DEBUG
At a MS-DOS prompt, type debug. DEBUG’s prompt is a dash (-). Type a question mark (?) to get a list of
available commands.
You may return to the DOS prompt by entering Q and carriage return (<CR>).
You may enter the key sequence (Ctrl) (PrtSc) to print the displayed information.
While in the DEBUG program, type D to initiate the dump command. The dump command displays the
contents of memory.

What occurs for this command?


The command also accepts the logical address. What happens if you type D1000:0400? How many
bytes are displayed?

There are three types of addresses, the physical address, the logical address, and the offset address. The
physical address if the 20 bit address that is actually put on the address pins of the microprocessor and
decoded by the memory interface. For the 80x86 CPUs, the address range is 00000H to FFFFFH for the
actual physical location in the RAM or ROM within 1 megabyte of memory. The offset address is the
location with in a 64 kbyte segement range. Therefore the offset range is from 0000H to FFFFH. The
logical address consist of the segment value and an offset address. For a code segment (CS:IP) with
logical address 2500:0010 has a physical address of 25010H. Shft CS left one bit -> 25000 and add IP (the
offset) 25000H+0010H = 25010H the 20 bit physical address.
How would you display memory locations 10000H thru 1000EH? Remember the physical address
location displayed is a combination of the segment address, the offset.
Use the ENTER command to load 12H, 13H, 14H into location 10000H (E1000:0000). The E command
displays the contents of the memory location and waits for new data or space to advance to the next
location. The number before the period is the contents of the memory before the change. If no change is
necessary, enter a space to go to the next location.

Use the Dump command to view the contents at location 10000H. Are the values you entered in
memory at that location?
We can also use the assemble command to enter data. Type A1000:0000 <CR> 1000:0000 DB
12,13,14 <CR> 1000:0003 <CR>. Use the dump command to display the contents of the segment
address 1000:0000,0002. What difference do you find between A and E?
The A command accesses a mini assembler. Example 1.1 is a short program that uses the DOS function
(option 9) to display a character string. The DOS function option 9 requires that the DS:DX register
combination address the character string and that AH is loaded with a 09H before executing the INT 21H
instruction. The INT 21 command accesses the DOS functions. The character string must end with a $.
The INT 3 provides a break point.
Example 1.1
-A0A88:0100 <CR>
MOV DX,0107
0A88:0103 MOV AH,9
0A88:0105 INT 21H
0A88:0107 DB ’This is my first assembly program$’
0A88:0129 INT 3
0A88:012A
Follow the example to store the program in memory. Use the U0100,0105 command to unassemble the
program and to display it on the monitor using DEBUG.
How does the displayed program differ from Example 1.1?
What is the logical address of the character string?
Type D0107 L21, how does the ascii text appear?
What is the logical address of the program? What is the physical address?
Once we are sure that the program is stored in memory, we can execute it using the G (Go) command. For
example, the G=1000:0000 command informs DEBUG to execute the program beginning at location
1000:0000. The = sign must precede the address. If a breakpoint is desired, it is entered as a second
parameter. Use the G command to execute the example program and stop it at offset address 0005.
(G=0100,0105).

Why don’t we include the code segment address (0A88:0100 in figure) in the G command?
What are the contents of the register?
What are the contents of all registers at the breakpoint?
Rewrite the program using INT 3 as the breakpoint, how does this change the G command?
Have the contents of the registers changed?
Issue the Register command to examine the contents of the internal registers.

How do the R command and the D command differ?


What is the physical address of the next instruction?
Use the R command to display the contents of IP then change them to 0200H, what instruction is
pointed to by CS:IP?
Draw a memory map to illustrate the contents of the memory and registers. Use the figure from pre-lab.
We can use the Register command to examine and modify the contents of the internal registers. Use the R
command to display the current contents of all the registers.
What are the contents of CS, DS, and SS?
If R is used with a single register, ie RCS, then the contents of that register are changed. Change CS to
the logical address for your ex 1 code segment and IP to 0100. Type G at the command line, what
happens?
The T (trace) command can be used to step through the program and display the contents of the register in
each step.

B. Loading DEBUG32
At a MS-DOS prompt, type debug32. Type a question mark (?) to get a list of available commands. You
may return to the DOS prompt by entering Q and carriage return (<CR>). You may enter the key sequence
(Ctrl) (PrtSc) to print the displayed information. While in the DEBUG32 program, initiate the dump
(display) command. The dump command displays the contents of memory.

Describe the differences from the DEBUG dump command.


Type CPU <CR>, what is displayed?
What is the function of the PR command? Was this command available with DEBUG?
What command would you use to display contents in 16 bit format? 32 bit format?
Use the A command for DEBUG to enter the following segment at logical address 1000H.
Example 1.2
MOV AL,4CH
ADD AL,3EH
INT 3

What are the contents of register AL?


Repeat the example using DEBUG32, is there a difference?
Draw the memory map for the DEBUG and the DEBUG32 results.

To load a program into debug32 use the load command. Use the load command and unassemble the
program ascii.exe provided on the diskette provide in the text in the directory Chap2. (Ask the TA what
directory the diskette has been stored on for lab.)

How many bytes of memory does the program take up?


Run the complete program by issuing the GO command, what is the starting address in the GO
command ?
Execute the program using the Trace command, does the starting address differ from GO?
What is your observation of the Trace Command?
What is the opcode for the POP command? What is the opcode for the MOV DX, 000EH command?

C. Saving your work


In order to save programs written in DEBUG, the program must be a .COM file. Use the N command in
DEBUG to name the file and give it the .COM extension. In order to execute as a .COM file, the starting
address must be 0100H. The file is saved with the W (write) command. Example 1.3 shows the sequence
to modify a current program to be saved and executed later.
Example 1.3
-RCS 2000
:1000
-RIP 1002
:0100
-NC:\HELLO.COM
-RBX 0200
:0000
-RCX 0200
:011C
-W
In this example, the CS:IP are modified by using the RCS and RIP DEBUG commands. Finally, the length
of the program (counted from 0100H) is placed in BX:CX before the W command is executed.
DO NOT specify any parameters with the W command or you will write over valuable PC
parameters.

What command do you use to name and save a file using DEBUG32?
Does the program have to reside at a certain address in order to be saved?
Why or why not?

Lab Report

A. Describing What You Learned


Answer all of the ‘‘Think About It’’ questions above.
Include the completed diagrams and memory maps.

B. Applying What You Learned


Write explanatory comments for example 1.1 to show the purpose of each instruction.
Write a short program that will display your name and your classification on the screen.

You might also like