Laboratory Exercise # 1: Debug Facility Part 1
Laboratory Exercise # 1: Debug Facility Part 1
1. Introduce the students to assembly language programming and the use of the tools that he/she will
need throughout the lab experiments;
2. Be familiar with the different commands used in DOS debug; and
3. Describe in detail the nature of assembly programs and write a laboratory report based on
findings.
BASIC INFORMATION
DEBUG is a program that is a part of the MS-DOS that allows the user to:
The DEBUG prompt is a hyphen or an underscore; commands are written after this prompt.
DEBUG Commands
THE R COMMAND
Format:
R <register name>
Example:
The command
-R AX
displays the contents of the register AX. Its execution causes the current value in
AX to be displayed. If, for instance, the accumulator contains 0000, this command
displays
AX 0000
:
If the value is to be unchanged, press the ENTER () key. Otherwise, enter the
new value after the colon (:) and press the ENTER () key.
Symbol Register
AX Accumulator register
BX Base register
CX Count register
DX Data register
SI Source index register
DI Destination index register
SP Stack pointer register
BP Base pointer register
CS Code segment register
DS Data segment register
SS Stack segment register
ES Extra segment register
F Flag register
Examples:
1. Issue commands to the debugger on the PC that will cause the value in BX to be
modified to FF00H and then verify that this new value exists in BX.
2. Use the register command to set the parity flag to even parity. Verify that the flag
has been changed.
This command, which stands for DUMP, examines the contents of a memory location or a
block of consecutive memory locations.
Format:
D <address>
The value of the address entered is automatically referenced to the current value in the
data segment (DS) register.
For all memory dumps, an ASCII version of the memory data is displayed to the right of
the hexadecimal data.
Repeated executions of the D command display, iteratively, the next 128 bytes of memory
locations.
To examine the data that are stored in the code segment, stack segment, or extra
segment, use the appropriate segment register name in the command.
Examples:
1. To examine two bytes of data that are at offsets equal to 0200H and 0201H in the
current data segment, enter the command:
2. Issue a dump command that will display the 32 bytes of memory locations that are
located at offsets 0300H through 031FH in the current data segment.
3. The commands needed to dump the values in the first 16 bytes of the current
code segment and extra segment are:
4. Use the DUMP command to examine the 16 bytes of memory just below the top of
the stack.
The top of the stack is defined by the contents of the SS and SP registers
(SS:SP). If the SP was initialized to FFEE when debug was loaded, the 16 bytes
of interest reside at offset FFEE through FFFD from the current value in SS. This
part of the stack is examined with the command:
The E (ENTER) command modifies the data stored in specific memory locations.
Format:
E <address> <list>
The address part of the E command follows the same notational semantics as in the D
command — if no segment name is included with the offset, the DS register is assumed.
The list that follows the address is the data values that are loaded into the specified
memory locations.
Issuing an E command with an address but no data displays the contents of the addressed
storage location. However, the programmer may opt to do one of three actions:
1. Press the enter key: this action terminates the ENTER command without
modifying the contents of the memory location.
2. Press the space bar: this action causes the contents of the next consecutive
memory location to be displayed.
3. Enter a new value of data: this modifies the contents of the specified memory
location and allows the programmer to continue with the next consecutive memory
location (by pressing the space bar) or to terminate the ENTER command (by
pressing the return key).
The ENTER command can also be used to enter ASCII data — this is done by enclosing
the data entered in quotation marks (single or double quotation marks can be used).
Examples:
1. The command that loads five consecutive byte-wide memory locations that start at
address DS:100 with the value FF is
-E DS:0100 FF FF FF FF FF ()
2. The command
causes the ASCII data for the letters A, S, C, I, and I to be stored in memory
locations with addresses DS:0200, DS:0201, DS:0202, DS:0203, DS:0204,
respectively.
THE F COMMAND
The F (FILL) command stores a block of consecutive memory locations with the same
data.
Format:
The starting address and the ending address specify the block of storage locations in
memory.
Examples:
1. The command
causes the 32-byte locations in the range DS:0100 through DS:011F to be loaded
with 22H.
2. Initialize all storage locations in the block of memory from DS:0120 through
DS:013F with the value 33H and the block of storage locations from DS:0140
through DS:015F with the value 44H. Verify that the contents of these ranges of
memory are correctly modified.
The initialization operations can be done with the FILL commands that follow:
THE A COMMAND
The A (ASSEMBLE) command assembles the instructions of a program, one after the
other, and stores them in the specified memory location.
Format
A <starting address>
The parameter starting address refers to the address at which the machine code of the
first instruction of the program is to be stored.
Examples:
1. To assemble the instruction ADD [BX + SI + 1234], AX and store its machine
code in the memory starting at address CS:0100, the command entry is:
A CS:0100 ()
Assuming that the code segment (CS) register is initialized to 0CDEH, the
response to this command input is the display of the starting address in the form:
0CDE:0100_
The instruction to be assembled is typed in following this address and when the
ENTER () key is pressed; the instruction is assembled into machine code. It is
thus stored in the memory and the starting address of the next instruction is
displayed. At this point, either the next instruction is entered or the ENTER () is
pressed to terminate the ASSEMBLE command.
2. Assume that the program listed below is to be stored in the memory starting at
address CS:0200. The assembler is invoked with the command:
A CS:0200 ()
Assuming that the code segment (CS) register contains the value OCDEH, this
gives the response:
0CDE:0200_
THE G COMMAND
The G (GO) command provides the option of executing the entire program or of executing
the program in several segments of instructions by using breakpoints.
Format:
The starting address is the address of the instruction at which execution is to begin.
The breakpoint address is the address of the end of the program segment (that is, the
address of the instruction at which execution is to stop).
The breakpoint address specified must correspond to the first byte of an instruction.
Examples:
1. The command
loads the IP register with 0200H, sets a breakpoint at address CS:0217, and then
begins program execution at address CS:0200. Instruction execution proceeds
until the address CS:0217 is accessed. When the breakpoint address is reached,
program execution is terminated, the complete internal status of the 8086 is
displayed, and control is returned to DEBUG.
2. The command
G=CS:0100 ()
executes a program that starts at offset 0100H in the current CS. This command
causes the program to run to completion. If the CS and IP are already initialized
with the correct values, the command:
G ()
THE T COMMAND
The T (TRACE) command steps through the program by executing one or more
instructions at a time.
Thus, this command allows the programmer with the ability to execute one instruction at a
time (this operation is known as single-stepping the program).
The single-step operation displays the contents of the registers or specified memory
locations before and after the execution of each instruction.
Format:
T =<address> <number>
Examples:
1. The command
T=CS:0100 ()
2. The command
T ()
executes the instruction pointed to by the current values of the CS and IP (CS:IP)
registers. This is the form of the TRACE command used to execute the next
instruction.
3. The command
T=CS:0100 3 ()
traces through three instructions. Again, the internal state of the 8086 is displayed
after each instruction is executed.
LABORATORY WORK
1. Issue a dump command that will display the 64 bytes of memory locations that are located at offsets
0500H through 053FH in the current data segment. Observe the memory data displayed to the right of
the hexadecimal data.
2. Execute the command below:
3. Repeat Step 1 and observe the memory data displayed to the right.
4. Initialize all storage locations in the block of memory from DS:0500 through DS:051F with the value
22H and the block of storage locations from DS:0520 through DS:053F with the value 44H. Verify that
the contents of these ranges of memory are correctly modified.
5. Assume that the program listed below is to be stored in the memory starting at address CS:0500.
Assemble the program below.