You are on page 1of 13

Experiment 1

DEBUG, Register and Memory Commands


Introduction
The DEBUG program is a program-execution/debug tool that operates in the IBMcompatible PCs disk operating system (DOS) environment. The DEBUG program is
found in any PC working with the 8088/8086 microprocessors family. The DEBUG
program, which is part of the PCs disk operating system (DOS), helps us to load, assemble,
execute, test, and debug programs written in assembly or machine code. Moreover, it gives
us the ability to directly access the internal registers and memory locations of the
microprocessors and make any necessary modifications to these registers or memory
locations.
The keyboard is the input unit of the debugger and permits the user to enter
command to lead data such as the machine code of a program; examine or modify the state
of the microprocessors internal registers; or execute a program. All we need to do is to
type in the command and then press the enter () key. These debug commands are the
tools a programmer needs to enter, execute and debug programs.
In this experiment, you will study DEBUG commands that can be used to examine
and modify the content of microprocessor registers and memory. The ability to examine
modify the content of registers and memory is essential for debugging programs. The
complete command set of the DEBUG program can be found in Table 1. It is very
important to refer to this table whenever you need information about the command set of
the DEBUG program.

Running the DEBUG program


1. The fastest way to lunch the debug program is to use the Run command. To do so,
press Win button and R button (Win + R), then type cmd or cmd.exe. This will
open window working in the DOS environment as the shown in Fig 1.

Fig 1
Page 1 of 13

2. Whether you are working under C, D, and Z directly or under any other directory,
such as (C:\ or D:\documents and settings\, etc) just type (DEBUG) in lowercase
or uppercase then press enter; as shown in Fig 2 or Fig 3. Notice the appearance
of a negative sign to the left indicating that the DEBUG program is now running.

Fig 2

Fig 3
3. Six kinds of information are typically entered as part of a command: a command
letter, an address, a register name, a file name, a drive name, and data. The entire
command set of DEBUG is shown in Table 1. This table gives the name for each
command, its function, and its general syntax. By syntax, we mean the order in
which key entries must be made to initiate the command.

Page 2 of 13

Table 1
Command

Syntax

Register

R Register name

Quit

Dump

D Address

Enter

E Address List

Fill

F Start-Add End-Add List

Move

M Start-Add End-Add Dest-Add

Compare

C Start-Add End-Add Dest-Add

Search

S Start-Add End-Add List

Input
I Address
Output
O Address, Byte
Hex
H Num1, Num2
Add/Subtract
Unassemble

U Start-Add End-Add

Name

N Filename

Write
Load

W Start-Add Drive Start-sector Numsectors


L Start-Add Drive Start-sector Numsectors

Assemble

A Start-Add

Trace

T =Address Number

Go

G = Start-Add Breakpoint-Add

Function
Examine or modify the contents of an
internal register
End use of the DEBUG program
Dump the contents of memory to the
display
Examine or modify the contents of
memory
Fill a block in memory with the data
in list
Copy a block of data from a source
location in memory to a destination
location.
Compare two blocks of data in
memory and display the locations
that contain different data
Search through a block of data in
memory and display all location that
match the data in list
Read the input port
Write the byte to the output port
Generate hexadecimal sum and
difference of the two numbers
Unassemble the machine code into its
equivalent assembler instructions
Assign the file name to the data to be
written to the disk
Save the contents of memory in a file
on a diskette
Load memory with the contents of a
file on a diskette
Assemble the instruction into
machine code and store in memory
Trace the execution of the specified
number of instructions
Execute the instructions down
through the breakpoint address

Part 1: The Register Command


1. Type: R ().
By typing this command, you will see some information as the shown in Fig 4.
Using this command directly after loading DEBUG program allows you to see the initial
state of the registers. The initial state depends on the DOS version and system
Page 3 of 13

configuration at the time the DEBUG command is issued. Using this Register command,
after that, allows you to examine the contents of the internal registers of the microprocessor
at any time. An example of the initial state is illustrated in Fig 4.

Fig 4

This command gives you information about the internal registers and their contents, the
status (or Flags) register, the next instruction to be executed and the address of this
instruction.
The internal registers shown are AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS and IP.
The content of each register is shown beside the register name. The register mnemonics
for the R command are shown in Table 2.
The flags shown by the status registers are the Overflow flag, Direction flag, Interrupt flag,
Sign flag, Zero flag, Auxiliary carry flag, Parity flag and Carry flag. The status of these
flags in Fig 4 is NV, UP, EI, PL, NZ, NA, PO and NC. The notations used for displaying
the status flags are shown in Table 3. Notice that all the values assigned to the registers,
except the Flag register, are in hexadecimal code.
Table 2

Symbol
AX
BX
CX
DX
SI
DI
SP
BP
CS
DS
SS
ES
IP
F

Register
Accumulator register
Base register
Counter register
Data register
Source Index register
Destination Index register
Stack Pointer register
Base Pointer register
Code Segment register
Data Segment register
Stack Segment register
Extra Segment register
Instruction Pointer register
Flag register
Page 4 of 13

Table 3

Flag
OF
DF
IF
SF
ZF
AF
PF
CF

Meaning
Overflow flag
Direction flag
Interrupt flag
Sign flag
Zero flag
Auxiliary Carry flag
Parity flag
Carry flag

Set
OV
DN
EI
NG
ZR
AC
PE
CY

Reset
NV
UP
DI
PL
NZ
NA
PO
NC

2. To modify or examine the value in any register you just have to type the register
command followed by the name of the register you want to modify or examine. For
example, to change the content of register AX to 1234, type the following sequence of
commands:
R
AX
()
AX
0000
:1234
()

This command gives you the value of AX and waits for you to enter the new value you
want AX to have, which is in this case 1234. This command can be also used to check the
value of AX without the need to modify its value, as shown below:
R
AX
()
AX
1234
:_
()

3. To modify or examine the value of the Flag register you just have to type the following
command:
R

()

The flag settings are displayed as


NV UP EI PL NZ NA PO NC
The meanings of these notations are shown in Table 3. To modify the flags, just type in
their new states (using the notations shown in Table 3) and press the return key. For
instance, to set the carry, zero and sign flags, enter
NV UP EI PL NZ NA PO NC ZR NG CY ()
Note that the new flag states can be entered in any order. To verify the changes made to
the flag register, simply enter another Register command for the flag register as follows:
Page 5 of 13

R
F
()
NV UP EI NG ZR NA PO CY

()

4.
To finish working with DEBUG and to return back to DOS the QUIT (Q) command
must be entered as seen below:
Q

()

5.
To end working with the DOS window you are working with type the following
command at any directory: EXIT ()

Part 2: Memory Commands: Dump, Enter and Fill


The Dump Command
The Dump command allows you to examine the contents of a memory location or a block
of consecutive memory locations.
1. Run DEBUG program and check contents of the internal registers of the
microprocessor. [Use one register command to do that]. Then change DS register to
have the value 0AF8.
Note: Your memory contents will be different from the contents displayed in the figures
of this experiment.
2. Type: D ().
Typing this form of the dump command will display a block of data consisting of 128
consecutive bytes starting at offset 010016 from the current value in DS. An example of
this command is shown in Fig 5.

Fig 5
Page 6 of 13

Notice that three blocks of information are shown after running this command. The first
block to the left is showing the addresses of the memory locations displayed, the block in
the middle is showing the contents of memory, and the block to the right is showing the
ASCII translation of these memory contents.
The 128 bytes are displayed in 8 lines. Each line is displaying 16 bytes (8 bytes to the left
and 8 bytes to the right separated by a hyphen). The content of each byte is displayed in
hexadecimal code. Notice that only the address of the first byte in the line is shown in the
address block, to the left of the line. It means that the addresses of only 8 memory locations
will be displayed. In Fig 5 the starting address of the memory block (the whole 128 bytes)
is 0AF8:0100 and the ending address is 0AF8:017F, and for the first line (first 16 bytes)
the starting address is 0AF8:0100 and the ending address is 0AF8:010F. As an example
from Fig 5, the contents of memory locations 0AF8:0100, 0AF8:0101, 0AF8:013B,
0AF8:0173, and 0AF8:017F are 1E, 99, 89, EB and A2 respectively. [Check these values
from Fig 5].
Notice also that for all memory dumps, an ASCII version of the memory data is also
displayed. It is displayed in a block consisting of 8 lines to the right of the hexadecimal
data block. All bytes that result in an unprintable ASCII character are displayed as the .
symbol.
3. Retype: D ().
Typing this command again will show the next 128 bytes of memory, as shown in Fig 6.
Notice here that the next block of displayed memory started exactly after the end of the last
block. This block of memory starts at address 0AF8:0180 and ends at address 0AF8:01FF.

Fig 6

Page 7 of 13

Executing this command again will result in showing the next 128 bytes of memory. It
doesnt matter whether you do this command again directly or after several other DEBUG
commands. Whenever you use this command again the block of memory that will be
displayed to the screen will be the one following the last block of memory displayed due
to the last Dump command.
4. Type: D 0200 ().
Typing this command will display 128 bytes of memory starting at address 0AF8:0200. In
other words, you can display any block of memory in DS by just giving an offset to where
you want your block of memory to start. Type D 020B () and see what happens. Can you
tell the difference?
5. Type: D 0AF8:0100 ().
6. Type: D DS:0100 ().
The commands in steps 5 & 6 have the same effect. In fact, they are also both equal to the
D 0100 command. As we mentioned before, the Dump command will automatically dump
memory locations in DS. So whether you specify the address of DS and its offset as in step
5, or just typing DS in letters and its offset as in step 6, or even ignoring mentioning the
DS as in the D 0100 command, you will still have the same result, as seen in Fig 7.

Fig 7
7. Type: D 0100 0113 ().
Typing a starting address and ending address after the Dump command will allow you to
see the specified bytes only without the need to display the whole 128 bytes of memory.
In this case we are displaying 20 bytes only, as seen in Fig 8.

Page 8 of 13

Fig 8
Is it possible to display more than 128 bytes at a time? Prove whether this is possible or
not. [Hint: use the command D 0100 019F () and see what happens].
8. Specifying one of the other three segment registers after the Dump command will allow
you to examine the contents of these segments. Try these commands:
D CS:0100 ().
D SS:0200 ().
D ES:0300 ().
Enter Command
The Enter command allows you to examine or modify the contents of a memory location
or a block of consecutive memory locations, and as the Dump command, it is examining
and modifying the contents of DS automatically as long as no other segment is mentioned.
1. Type: E DS:0100 01 02 03 04 05 06 ().
Typing this form of the Enter command will allow you to load the memory at locations
DS:0100, DS:0101, DS:0102, DS:0103, DS:0104 and DS:0105 with 01, 02, 03, 04, 05, and
06 respectively. You can examine these changes by typing a dump command as seen in
Fig 9.

Fig 9
2. Type: E DS:0100 ().
This command will not only allow you to see the contents of memory at location DS:0100,
but will also wait for you to either modify this memory location by typing any hexadecimal
number or return to the DEBUG program by pressing the () key. However, if you press
the space bar key you will be able to see the content of the next memory location
(DS:0101), as seen in Fig 10. Notice here that the contents of memory location DS:0103
was modified to be FF.

Fig 10

Page 9 of 13

Pressing the minus sign - instead of the space bar will move you backward towards the
previous memory location to examine or modify it as seen in Fig 11. Notice here that the
contents of memory locations DS:0102 & DS:0101 were modified again to be 5C & 37
respectively.

Fig 11
3. Type: E DS:0100 UAE University ().
This command causes the ASCII data for the letters between the quotation to be stored
in memory starting at address DS:0100 and ending at address DS:010D, as seen in Fig8. You can verify this character data by typing the command
D DS:0100 010D ()
Looking at the ASCII field of the data dump shown in Fig 12, you can see that the
correct ASCII data were stored in memory. Actually, either single-quote or doublequote marks can be used. Therefore, the entry could also have been made as
E DS:0100 UAE University ()

Fig 12
4. Make sure to change the contents of ES, SS, and CS to be 1000, 2000, and 3000
respectively. [Use 3 register commands to achieve this task].
5. Type: E CS:0100 35 8b 72 CA ().
This command will allow you to modify memory locations in CS. The memory
locations CS:0100, CS:0101, CS:0102, and CS:0103 are now modified to be 35, 8B,
72, and CA. You can examine these changes by typing the command D CS:0100 0103
(). You can also see the effect of changing these bytes by dumping the internal
registers and checking the modifications made to the next instruction to be executed
(using the R () command), as seen in Fig 13. You will notice here that the changes
made to these memory locations in CS changed the next instruction to be executed.
You can also examine or modify any memory locations in ES and SS as well as the DS
and CS.

Page 10 of 13

Fig 13
Fill Command
The Fill command allows you to fill a block of consecutive memory locations all with the
same data. The same job can be done by the Enter command, by entering the data address
by address. But the Enter command would be here very time and effort consuming. And
as the Dump and Enter commands, it is filling memory contents in DS automatically as
long as no other segment is mentioned.
1. Type: F 0200 025F A0 ().
Typing this form of the Fill command will allow you to load each byte of the memory
block starting at address DS:0200 and ending at address DS:025F (that is 96
consecutive bytes) with A0. You can examine these changes by typing a dump
command as seen in Fig 14.

Fig 14
2. Type: F ES:0200 025F 12 34 56 78 ().
Typing this form of the Fill command will allow you to load each consecutive 4 bytes
of the memory block starting at address ES:0200 and ending at address ES:025F (that
is 96 consecutive bytes) with 12, 34, 56, and 78. You can examine these changes by
typing a dump command as seen in Fig 15. This command is showing us that we can
fill any block of data not only in DS and ES, but also in CS and SS. Moreover, the
number of consecutive data bytes mentioned in the Fill command to be filled is not
limited by 4 bytes, actually it can be any number of bytes.

Page 11 of 13

Fig 15
3. Type: F DS:1000 1126 Al-Ain City, UAE ().
This is another form of the Fill command where you can fill a block of memory with
ASCII character data. Again, you can examine the changes made to the memory
locations by typing a dump command as seen in Fig 16.

Fig 16

Page 12 of 13

Exercises
Try to answer the following questions. It will help you during quiz next week.
1. What purpose is served by the DEBUG program?
2. Can DEBUG be brought up by typing the command using lowercase letter?
3. If the DEBUG command R AXBX is entered to a PC, what happens?
4. Write the command needed to change the state of the parity flag to PE.
5. Write the Register command needed to change the value in CX to 1016.
6. What happens when you try to change the value in DX to 50OA?
7. Write a command that will dump the state of the microprocessors internal registers.
8. How many registers are displayed with the R command?
9. What is the meaning of DF, SF, AF and IF?
10. What is the instruction that appears when using the R command?
11. Write a Dump command that will display the contents of the first 32 bytes of the current
code segment.
12. What is the minimum and maximum number of bytes that can be displayed using the
Dump command?
13. How many number of bytes can be displayed by typing the D () command 12
consecutive times?
14. Show an Enter command that can be used to examine the contents of the first 9 bytes
of the extra segment.
15. Show the Enter command needed to load five consecutive bytes of memory starting at
address CS:0100 of the current code segment with D3, then show how you can return
back to location CS:0103 and change it to be 12.
16. Show how to write your name using the Enter command at location DS:1010.
17. Is it true that the Hexadecimal code is the translation found for the instruction shown
using the R command?

Page 13 of 13

You might also like