You are on page 1of 4

Microprocess

or System

Name Date Performed

Course & Year Instructor’s Signature

Offer Number Rating

Experiment No. 1
DOS Debug Command
Objective:
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.

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.

Figure 1. DEBUG Environment


Debugging Functions
Some of the basic functions that the debugger can perform are the following:
• Assemble short programs
• View a program’s 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

Debug Commands:
The following table shows a list of some commonly used DEBUG commands.

Invoking Debug:
To invoke the DEBUG program, a user opens command promote window and enters the following:
COMMANDS IN DEBUG

Entering and exiting DEBUG


 Run DOSBOX, then type
Z :\MOUNT C D:\ <return>
 Change its drive to C, type
Z :\ C: <return>
 At the C drive, enter the DEBUG program, simply type its name at the DOS level:
C :\> DEBUG<return>
After DEBUG and enter key (carriage return) have been entered, the DEBUG prompt “ -“ will appear on the following line. DEBUG is
now waiting for you to type in a command.
 To exit Debug, simply type Q (quit command) after the DEBUG prompt:
- Q <return>
After the Q and enter key (carriage return) have been entered, DEBUG will return you to the DOS level.
Examining and altering the contents of registers
 R, the REGISTER command. The register (R) command allows you to examine and/or alter the contents of the internal registers
of the CPU. The R command has the following syntax:
- R <register name>
The R command will display all registers unless the optional <register name> field is entered, in this case only register named will be
displayed and/or altered.
Coding and running programs in DEBUG
 A, the ASSEMBLE command. The assemble command is used to enter assembly language instructions into memory.
- A <starting address>
The starting address may be given as an offset number, in which case it is assumed to be an offset into the code segment, or the
segment register can be specified explicitly.
 U, the UNASSEMBLE command. The unassembled command displays the machine code in memory along with their equivalent
assembly language instructions. The command can be given in either format shown below:
- U <starting address> <ending address>
- U <starting address> <L number of bytes>
If the U command is entered with no addresses after it: “U <return>”, then DEBUG will display 32 bytes beginning at CS:IP.
 G, the GO command. The GO command instructs DEBUF to execute the instructions found between the two given addresses.
Its format is:
- G <=starting address> <stop address(es)>
If no addresses are given, DEBUG begins executing instructions at CS:IP until a breakpoint is reached. After a breakpoint is reached,
DEBUG displays the register contents and returns you to the command prompt. Up to 10 stop addresses can be entered.
DEBUG will stop execution at the first of these breakpoints that it reaches.
 T, the TRACE command. The trace command allows you to trace through the execution programs one or more instructions at a time
to verify the effect of the programs on registers and/or data. Its format is:
- T <=starting address> <number of instructions>
The trace command functions similarly to GO command in that if no starting address is specified, it starts at CS:IP.
Data Manipulation in DEBUG
 D, the DUMP command. The dump command is used to examine the contents of memory. The syntax of the D command is as
follows:
- D <start address> <end address>
- D < start address> <L number of bytes>
The D command can also be entered by itself, in which case debug will display 128 consecutive bytes beginning at DS:100.
 F, the FILL command. The fill command is used to fill an area of memory with a data item. The syntax of the F command is as follows:
- F <starting address> <ending address> <data>
- F <starting address> <L number of bytes> <data>
This command is useful in filling a block of memory with data, for example to initialize an area of memory with zeros.
 E, the ENTER command. The enter command can be used to enter a list of data into a certain portion of memory.
- E <address> <data list>
- E <address>
For example, - E 100 ‘John Smith’. This example showed how to enter ASCII data, which can be enclosed in either single or double
quotes.
Loading and Writing programs
 N, the NAME command. The name command initializes a filename in memory before using the load and write commands.
 Its format is :
- N <drive name:> <filename> <extension name>
After the code has been entered with the A command, CX must be set to contain the number of bytes to be saved and register BX must
be set to 0.

 W, the WRITE command. The write command is used to save instructions onto a disk. Its format is:
-W
 L, the LOAD command. The load command performs the opposite function of Write command. It loads from disk into memory
starting at the specified address. Its syntax is:
-L
FLAG REGISTERS

The complete set of possible flag mnemonics in Debug (order from left to right) are as follows:

Set Clear
OV = Overflow NV = No Overflow
DN = Direction Down UP = Direction Up
EI = Interrupts Enabled DI = Interrupts Disabled
NG = Sign Flag negative PL = Sign Flag Positive
ZR = Zero NZ = Not Zero
AC = Auxiliary Carry NA = No Auxiliary Carry
PO = Odd Parity PE = Even Parity
CY = Carry NC = No Carry

The R command also displays the next instruction to be executed:

Procedure:
DEBUG Environment
1. Type DEBUG at the command prompt of DOS then press ENTER key.
2. Command: R
A. You will see a dash “-“ prompt that signifies DEBUG environment. Type R/r on this prompt then ENTER key. Illustrate the output:

B. Type the following commands. Write the contents or observation on the space provided:
REGISTER COMMAND CONTENTS/OBSERVATION
IP -R IP
CX -R CX
AX -R AX
DX -R DH

C. Write the appropriate command to modify the contents of the following registers.
REGISTER NEW CONTENTS COMMAND
AX 0001
CX 0021
IP 0100

3. Command: A
Assemble the given program at the starting offset address 100h. Type A 100 then press ENTER key. Encode the program written
below:
CS:0100 MOV AX,1
MOV BX,2
MOV CX,3
ADD AX,BX
ADD AX,CX
INT 3
4. Command: U
A. Write the command that will unassemble the program in number 3:

Command: __________________________________________

B. What are the equivalent machine codes of the following instructions?


INSTRUCTION MACHINE CODE
MOV AX,01
MOV CX,3
ADD AX,BX

5. Command: G
A. Execute the program in number 3. Type the given command

Command:
B. What are the contents of the following registers?
AX BX CX

6. Command: T
A. Reset the values of AX, BX and CX and set value of IP to 0100.
B. Execute program given in number 3 using trace command.
C. Type T or t at the DEBUG prompt, then press ENTER key. Repeat this step until all instructions are executed.
D. What are the contents of the following registers after executing each instruction?

INSTRUCTION AX BX CX
MOV AX,1
MOV BX,2
MOV CX,3
ADD AX,BX
ADD AX,CX

7. Command: D
A. Illustrate or describe the output after executing the following D commands:
COMMAND OUTPUT
D 100 10F

D CS:110 120

B. Type in the command: __________


No. of bytes displayed: ___________
Beginning Address: ______________
Ending Address: ________________

8. Command: F
A. Determine the contents of the following blocks of memory, after executing the F commands. You may use the D command to
display the contents:
COMMAND BLOCK OF MEMORY DATA CONTENTS
- F 100 10F FF 100 – 10F

- F 100 L20 00 FF 100 – 11F

B. Fill the following blocks of memory with the specified data. Write the appropriate command.
BLOCK OF MEMORY DATA COMMAND
100 - 110 00

11F – 130 00,01,10,11 (alternately)

9. Command: E
A. Enter the data ‘John Snith’ at starting address 100h:
Command: ______________________________________
B. Modify the data ‘John Snith’ to ‘John Smith’ (ASCII code of m=6D)
Command: ______________________________________

10. Command: N, W, L
A. Assemble the given program at starting address 100h. Write the command on the space provided.
Command: ____________________________________
CS:0100 MOV CX,05
CS:0103 MOV BX,0200
CS:0106 MOV AL,0
CS:0108 ADD AL,[BX]
CS:010A INC BX
CS:010B DEC CX
CS:010C JNZ 0108
CS:010E MOV [0205],AL
CS:0111 INT 3

B. Name the file ”LAB1.com” and save it in drive C. Set the value of CX with the total number of bytes of the program and set BX to 0
before saving. Write the commands for naming and saving the file.
Command (Naming): ____________________________
Command (Saving): _____________________________
Note: Check the file in drive C.

C. Exit from DEBUG and load the saved file (LAB1.com) by typing DEBUG LAB1.com from the DOS prompt. Use Unassemble command;
do you see the program code LAB1.com? ________

You might also like