EE 390 Lab Manual, EE Department, KFUPM
Experiment #1
MS-DOS Debugger (DEBUG)
1.0 Objectives:
The objective of this experiment is to introduce the "DEBUG program that comes with
MS-DOS and Windows operating systems. This program is a basic tool to write, edit and
execute assembly language programs.
In this experiment, you will learn DEBUG commands to do the following:
Examine and modify the contents of internal registers
Examine and modify the contents of memory
Load, and execute an assembly language program
1.1 Introduction:
DEBUG program which is supplied with both DOS and Windows, is the perfect tool for
writing short programs and getting acquainted with the Intel 8086 microprocessor. It
displays the contents of memory and lets you view registers and variables as they change.
You can use DEBUG to test assembler instructions, try out new programming ideas, or to
carefully step through your program. You can step through the program one line at a time
(called tracing), making it easier to find logic errors.
1.2 Debugging Functions
Some of the basic functions that the debugger can perform are the following:
Assemble short programs
View a programs source code along with its machine code
View the CPU registers and flags (See Table 1 below)
Trace or execute a program, watching variables for changes
Enter new values into memory
Search for binary or ASCII values in memory
Move a block of memory from one location to another
Fill a block of memory
Load and write disk files and sectors
EE 390 Lab Manual, EE Department, KFUPM
The following table shows a list of some commonly used DEBUG commands.
SYNTAX
COMMAND
Register
Dump
FUNCTION
R [Register Name]
internal register of the CPU
-RF
-D start-add end-add
Enter or modify the contents of the
-E DS:100 22 33
specified memory locations
-E address data data
Fill a block of memory with data
-F DS:100 120 22
Convert assembly lang. instructions
-A CS:100
into machine code and store in memory
-A start-address
Display the assembly instructions and
-U CS:100 105
its equivalent machine codes
-U start-add end-add
Line by line execution of specific
-T=CS:100
number of assembly lang. instructions
-T=starting-address
G [Starting Address]
Execution
-G=CS:100 117
[Breakpoint Add.]
instructions until Breakpoint address
A [Starting address]
Un-assemble
U [Starting Address]
Trace
T [Address][Number]
of
contents
of
assembly
memory
ZR (zero flag)
locations specified by Address
Assemble
the
(AX reg.)
Addr]
Addr] [Data]
Go
-R AX
Display
F [Start Addr] [End
Fill
Examine or modify the contents of an
D [Start Addr] [End
E [Address] [Data]
Enter
EXAMPLE
-D DS:100 200
language
-G=start-add end-add
Table 1: DEBUG commands
The status flags of the 8086 uP can be set and reset using the R F command. For
example,
- R F NZ
; this command will reset the zero flag
- R F ZR CY PE
; this command will the zero, carry and parity flags
The Internal Registers and Status Flags of the 8086 uP are shown in the following tables.
Flag Meaning SET RESET
Flag Meaning SET RESET
CF
Carry
CY
NC
SF
Sign
NG
PL
PF
Parity
PE
PO
IF
Interrupt
EI
DI
AF
Auxiliary
AC
NA
DF
Direction
DN
UP
ZF
Zero
ZR
NZ
OF
Overflow
OV
NV
AX
BX
CX
DX
SI
DI
SP
BP
DS
CS
ES
SS
IP
8086 Internal Registers
Table 2: Internal Registers and Status Flags
2
EE 390 Lab Manual, EE Department, KFUPM
1.3 Pre-lab:
Part 1
1. Practice the debug commands shown in Table 1 above. You may also refer to the
chapter on debug commands in your text book for examples.
Part 2
1. Name a few computer operating systems. Which operating system do you mostly
use?
2. What is the full form for MS-DOS?
3. What is the difference between a logical address and a physical address? Show
how a physical address is generated from a logical address.
4. What are the following registers used for: DS, CS, SS, SP, IP, AX
5. Define the function each of the following flag bits in the flag register: Overflow,
Carry, Sign, and Zero.
EE 390 Lab Manual, EE Department, KFUPM
1.4 Lab Work:
A. Loading the DEBUG program
1. Load the DEBUG program by typing debug at the MS-DOS prompt, as shown in
the example below:
C:\WINDOWS>debug
2. You will see a dash (-) in the left-most column on the screen. This is the DEBUG
prompt.
3. Type a (?) to see a list of available commands.
4. Return to MS-DOS by entering Q. What prompt do you see?
Note: You have to hit Carriage Return (CR) key (or ENTER key) on the keyboard
after you type any debug command.
B. Examining and modifying the contents of the 8086s internal registers
1. Use the REGISTER command to display the current contents of all the internal
registers by typing R.
o List the values of the following registers:
AX
SP
BX
CS
CX
DS
DX
SS
IP
ES
o What is the address of the next instruction to be executed?
o What is the instruction held at this address?
2. Enter the command: R AH (hit ENTER key)
What happens? Can you find out why?
3. Use a REGISTER command to first display the current contents of BX and then
change this value to 0020.
EE 390 Lab Manual, EE Department, KFUPM
4. Use a REGISTER command to first display the current contents of IP and then
change this value to 0200.
5. Use a REGISTER command to first display the current contents of the flag
register and then set the parity, zero, and carry flags.
6. Redisplay the contents of all the internal registers. Compare the displayed register
contents with those observed in step 1 above. What instruction is now pointed by
CS: IP?
C. Examining and modifying the contents of memory
1. Use the DUMP command (D) to display the first 100 bytes of the current data
segment.
2. Use the DUMP command (D) to display the first 100 bytes of the code segment
starting from the current value of CS: IP.
3. Use the ENTER command (E) to load locations CS:100, CS:102, and CS:104
with 11, 22, and 33, one-by-one respectively.
4. Use the ENTER command (E) to load five consecutive byte-wide memory
locations starting at CS:105 with data FF.
5. Verify the result of steps 3 and 4 using the DUMP command.
6. Use the FILL command (F) to initialize the 16 storage locations starting at DS:10
with the value AA, the 16 storage locations starting at address DS:30 with
BB, the 16 storage locations starting at address DS:50 with CC, and the 16
storage locations starting at address DS:70 with DD
7. Verify the result of step 6 using the DUMP command.
EE 390 Lab Manual, EE Department, KFUPM
D. Coding instructions in 8086 machine language
1. Enter each of the following instructions starting at address CS:100 one-by-one
using the ASSEMBLE command (A).
MOV AX,BX
MOV AX, AAAA
MOV AX,[BX]
MOV AX,[0004]
MOV AX,[BX+SI]
MOV AX,[SI+4]
MOV AX,[BX+SI+4]
2. Using the UNASSEMBLE command (U), obtain
a. the machine code of each of the instructions in step 1
b. the number of bytes required to store each of the machine code
instructions in step 1.
c. the starting address of each instruction.
Instruction
Machine Code Bytes required Starting Address
MOV AX, BX
MOV AX, AAAA
MOV AX,[BX]
MOV AX,[0004]
MOV AX,[BX+SI]
MOV AX,[SI+4]
MOV AX,[BX+SI+4]
d. Why are the starting addresses of the above instructions not consecutive?
EE 390 Lab Manual, EE Department, KFUPM
E. Writing an assembly language program
1. Using the ASSEMBLE command (A), load the program shown below into
memory starting at address CS: 0100. Dont type the number (0109) to the left of
the instruction when you enter the instruction.
MOV
MOV
MOV
0109: MOV
MOV
INC SI
INC DI
DEC
JNZ
SI, 0200
DI, 0300
CX, 0010
AH, [SI]
[DI], AH
CX
0109
2. Verify the loading of the program by displaying it with the UNASSEMBLE (U)
command.
a. How many bytes of memory does the program take up?
b. What is the machine code for the DEC CX instruction?
3. Fill 16 bytes of memory locations starting at DS: 0200 with value 45 and verify.
4. Dump 16 byte-wide memory locations starting at DS:0300 to check their contents.
5. Execute the above program one instruction at a time using the TRACE command
(T). Observe how the values change for registers: AX, CX, SI, DI flag register,
and IP.
6. Run the complete program by issuing a single GO command (G).
a. What is the starting address for this command?
b. What is the ending address for this command?
7. What are the final values of registers: AX, CX, SI, and DI?
8. Check the contents of 16 memory locations starting from address DS:300.
Compare the values of these locations with the values in locations starting from
DS:200.
9. Describe the function of the above program.
EE 390 Lab Manual, EE Department, KFUPM
F. Music Program
This program generates a musical tone every time a key is pressed. It generates 8 tones in
total and then stops.
1. Using the ASSEMBLE command (A), load the program shown below into
memory starting at address CS: 0100. When you type the instructions, dont type
the numbers (0104, 0124, 012C) that appear to the left of some instructions.
Note: The program shown below can also be typed in a notepad editor (instead of
directly typing in DEBUG one instruction at a time) and then can be pasted into
DEBUG. Check with your instructor if you need help in doing this.
0104:
MOV SI, 012C 0124:
CLD
MOV AH, 0
INT 16
LODSW
012C:
MOV BX, AX
CMP AX, 0
JZ 0124
MOV AL, B6
OUT 43, AL
MOV AL, BL
OUT 42, AL
MOV AL, BH
OUT 42, AL
IN AL, 61
OR AL, 3
OUT 61, AL
JMP 0104
IN AL, 61
AND AL, FC
OUT 61, AL
INT 20
DW 11D1
DW 0FDF
DW 0E24
DW 0D59
DW 0BE4
DW 0A98
DW 0970
DW 08E9
DW 0000
2. Verify the loading of the program by displaying it with the UNASSEMBLE (U)
command.
3. Run the complete program by issuing a single GO command (G).
a. What is the starting address for this command?
b. What is the ending address for this command?