You are on page 1of 6

Introduction To Debug

Introduction
This chapter will help in observing the contents of the microprocessor and all of the
memory locations that the processor can address. DOS program named Debug will allow
you to view memory, to enter programs in memory and to trace their execution. This will
give detail about how to enter the programs directly into a code segment and provides the
explanation of each execution step. This tool is very easy to use and universally available
on all Dos machines compare to the code view which is more sophisticated that comes
along with Microsoft assembler
Starting Debug
There are two methods to start the debug command
Method 1 :
At the dos prompt type debug and press enter . This will given an hypen (-) which means
the debug is waiting for one of its one letter command .
Method 2:
At the dos prompt type debug \path\filename and press enter. Debug will then load itself
into memory along with the file that is specified in the path\filename field of the
command line and put the first byte of the file at offset 100 of the work area. This will
help to debug the program written by us.
Rules of Debug command
It does not distinguish between lower case and upper case letters.
It assumes that all numbers are in Hexadecimal unlike Microsoft assembler, which
assumes numbers to be decimal.
Segment and offset are specified as segment: offset.
Spaces in commands are used only to separate parameters
8086 Register Set :
General Purpose Registers
AX (AH,AL)
BX (BH,BL)
CX (CH,CL)
DX (DH,DL)

Accumulator : Main arithmetic register


Base
: Generally used as a memory base or offset
Counter : Generally used as a counter for loops
Data
: General 16-bit storage, division remainder

Offset Registers
IP Instruction pointer : Current instruction offset
SP Stack pointer
: Current stack offset

BP Base pointer
: Base for referencing values stored on stack
SI Source index
: General addressing, source offset in string ops
DI Destination index : General addressing, destination in string ops
Segment Registers
CS
SS
DS
ES

Code segment
Stack segment
Data segment
Extra segment

: Segment to which IP refers


: Segment to which SP refers
: General addressing, usually for program's data area
: General addressing, destination segment in string ops

Flags Register (Respectively bits 11,10,9,8,7,6,4,2,0)


OF Overflow flag - Indicates a signed arithmetic overflow occurred
DF Direction flag -Controls incr. direction in string ops (0=inc, 1=dec)
IF Interrupt flag
-Controls whether interrupts are enabled
TF Trap flag
: Controls debug interrupt generation after instructions
SF Sign flag
: Indicates a negative result or comparison
ZF Zero flag
: Indicates a zero result or an equal comparison
AF Auxiliary flag : Indicates adjustment is needed after BCD arithmetic
PF Parity flag : Indicates an even number of 1 bits
CF Carry flag : Indicates an arithmetic carry occurred
Note :
The 8086 CPU uses a method SEGMENT: OFFSET scheme (explained later) which
converts 16 bit address to 20 bit address to calculate the effective address
Debug Commands
Debugs set of commands lets you perform a number of useful operations.
A
Assembles symbolic instructions into machine code
D
display the contents of an area of memory in hex format
E
Enter data into memory beginning at specific location
G
Run the executable program in the memory (Go)
P
Proceed, Execute a set of related instructions
Q
Quit the debug session
R
Display the contents of one or more registers in hex format
T
Trace the execution of on instruction
U
Unassemble machine code into symbolic code
?
Debug Help
R, the Register command: examining and altering the content of registers
In DEBUG, the register command R allows you to examine and/or alter the contents of
the internal CPU registers.

R <register name>
The R command will display the content of all registers unless the optional <register
name> field is entered. In which case, only the content of the selected register will be
displayed. The R command also displays the instruction pointed to by the IP. The R
command without the register name field, responds with three lines of information. The
first two lines show you the programmers model of the 80x86 microprocessor. (The first
line displays the contents of the general-purpose, pointer, and index registers. The second
line displays the current values of the segment registers, the instruction pointer, and the
flag register bits). The third line shows the location, machine code, and Assembly code of
the next instruction to be executed.
Question 1
When DEBUG is first invoked, what are the values in the general-purpose registers?
What is the reason for setting [IP] = 0100 ?
Recall that if the optional <register name> field is specified in the R command,
DEBUG will display the contents of the selected register and give you an opportunity to
change its value. Just type a <return> if no change is needed, e.g.
- r CX
CX 0000
: FFF
- r CX
CX 0FFF
:
Note that DEBUG pads input numbers on the left with zeros if fewer than four digits are
typed in.

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. Otherwise, CS can also be specified explicitly. (eg. A
100 and A CS:100 will achieve the same result). When this command is entered,
DEBUG will begin prompting you to enter Assembly language instructions. After an
instruction is typed in and followed by <return>, DEBUG will prompt for the next
instruction. This process is repeated until you type a <return> at the address prompt,
at which time DEBUG will return you to the debug command prompt.
Use the A command to enter the following instructions starting from offset 0100H.
-A cs:100
xxxx:0100 mov ax,1
xxxx:0103 mov bx,2
xxxx:0106 mov cx,3

xxxx:0109 add ax,bx


xxxx:010B add ax,cx
xxxx:010D jmp 100
xxxx:010F <enter>
where xxxx specifies the address of the code segment. Please note that the second
instruction starts at xxxx:0103. This implies that first instruction is three bytes long.
U, the Unassemble command: looking at machine code
The unassemble 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 100 10D
xxxx:0100
B80100 mov ax,1
xxxx:0103
BB0200 mov bx,2
xxxx:0106
B90300 mov cx,3
xxxx:0109
01D8
add ax,bx
xxxx:010B
01C8
add ax,cx
xxxx:010D
EBF1
jmp 100
Note: If the ending address is not specified then the U command unassembles 32 bytes
beginning from the starting address.
U <starting address> <L number of bytes in hex>
U 100 L 0d
Type in this command, check the result and explain

T, the Trace command: single-step execution


The trace command allows you to trace through the execution of your programs one or
more instructions at a time to verify the effect of the programs on registers and/or data.
Ex1: T < =starting address> < number of instructions>
T =100 5
If you do not specify the starting address then you have to set the IP using the R
command before using the T command
Ex2: Now try using r command to set IP to 100 and then execute T 5
Ex3: Now try using r command to set IP to 100 and then execute T
Now trace through the above sequence of instructions that you have entered and examine
the registers.
G, the Go command
The go command instructs DEBUG to execute the instructions found between the starting
and stop addresses.
G < = starting address > < stop address >
Ex: Execute the following command and explain the result

G = 100 10d
Caution: the command G= 100 10e will cause the system to hang. Explain why?
Often, it is convenient to pause the program after executing a few instructions, thus
effectively creating a break point in the program. For example, the command g 106
tells the DEBUG to start executing the next instruction(s) and pause at offset 0106H. Try
executing the sequence of instructions you entered using several options of the G
command.
The main difference between the GO and TRACE commands is that the GO command
lists the register values after the execution of the last instruction while the TRACE
command does so after each instruction execution.
Before proceeding to study the next command, you should reset DEBUG so that it points
to the first instruction of your program.

EXAMINING THE FLAG REGISTER


Exit and enter DEBUG again so that we start with the default flag bits. Use the A
command to enter the following program fragment beginning at address offset 0100H.
mov al, 9c
mov dh, 64
add al, dh
Notice when DEBUG was first entered, the flag bits, except for the interrupt bit, are all
cleared. So the original values are:
[NV UP EI PL NZ NA PO NC].
Execute the three instructions using either the G or the T command. When the above
three instructions have been executed, the flag register bits become:
[NV UP EI PL ZR AC PE CY]
Note: 1001 1100 + 0110 0100 = 0000 0000 .
Explanation of the affected flag bits:
Carry bit is set (from NC to CY ) since there is a carry beyond data bit D7.
Parity bit is set (from PO to PE ) since there is an even numbers of 1s ending in al.
Auxiliary bit is set (from NA to AC ) since there is a carry from data bits D3 to D4.
Zero bit is set (from NZ to ZR ) since the result is zero.
Sign bit is cleared (it was PL) since the result in binary representation is non-negative.
Now exit, re-enter DEBUG and run the two program segments (i) and (ii) given below.
Remember to begin each program at address-offset 0100H. Use the U command to
ensure that the programs have been entered correctly before executing them. Trace each
program and analyze the flag bits that are being affected.
(i) mov ax, 34f5
add ax, 95eb
(ii) mov bx, aaaa
add bx, 5556

Question 2 What are the final values in AX and BX after running each program
segment? List the flag the flag bits that have changed and explain how they have
changed.
EXAMINING MEMORY LOCATIONS
D, the dump command: examining the contents of memory
The dump command is used to examine the contents of memory. The display area
consists of three parts. To the left is the Hex address of the left most displayed byte. The
wide area in the center is the hex representation of the displayed area. To the right is the
ASCII representation of the displayed area.
D < starting address > < end address >
D < starting address > < L number of bytes >
Question 3 Use the U and D commands to look at one of your program segments
using the <L number of bytes > option. What is the difference between the two
commands?
COM (serial) ports and LPT (printer) ports of your PC
In an 80x86-based PC, there can be as many as 4 COM ports and 4 LPT ports present.
When the PC is turned on, DOS tests for each of the COM and LPT port. If the COM
ports are installed, their I/O port addresses (similar to memory address) are written to
memory locations 0040:0000 - 0040:0007. If the LPT ports are installed, their I/O port
addresses are written to memory locations 0040:0008 - 0040:000F; otherwise zeros will
be found in these memory locations.
Question 4: Give the appropriate DEBUG commands that will find out the number of
COM and LPT ports installed in your PC. List their port addresses.
ROM BIOS
The ROM BIOS of a PC is placed at memory addresses starting from F000:E000.
The 8-byte memory starting at address F000:FFF5 shows the date when the ROM BIOS
was programmed.
Question 5 : Give the command to look at these 8-bytes. On what date was the ROM
BIOS of your PC programmed? Normally D Command displays 128 bytes but in this
case it displayed only 11 bytes. Explain?
E, the Enter Command
E address
You can modify the content of any memory location in the data segment using the E
command
**************

You might also like