Using the DEBUG Program

Download Report

Transcript Using the DEBUG Program

Riyadh Philanthropic Society For Science
Prince Sultan College For Woman
Dept. of Computer & Information Sciences
CS 251
Introduction to Computer Organization
& Assembly Language
Lecture 15
Debug Program

Introduction

A demo program

Using the debug program
Debug Program
2

The DEBUG program provides an environment in which a program may be tested.

The user can step through a program, and display and change the registers and
memory.

It is also possible to enter assembly code directly, which DEBUG converts to machine
code and stores in memory.
Debug Program
3
TITLE demo: CHECK FLAGS
; used in DEBUG to check flag settings
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AX,4000H
; AX = 4000h
ADD AX, AX
; AX = 8000h
SUB AX, 0FFFFH ; AX = 8001h
NEG AX
; AX = 7FFFh
INC AX
; AX = 8000h
MOV AH, 4CH
; DOS exit function
INT 21H
; exit to DOS
MAIN ENDP
END MAIN
Debug Program
4

To enter DEBUG, (after assembling and linking the code) type:
c:\asm>DEBUG demo.exe

DEBUG responds by its prompt, “-”, and waits for a command to be entered.

Basic DEBUG commands:
 R: to view the registers.
 T: to trace the program.
 G: to complete execution of the program.
 Q: to exit the DEBUG program
Debug Program
5
• To view the registers, type R:
-R
AX=0000 BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=0000 NV UP EI PL NZ NA PO NC
1A0A:0000 B80040
MOV AX, 4000
Address of the
next instruction
to be executed
Machine code of
the next instruction
to be executed
Current flag settings
Debug Program
6
Status Flag
CF
PF
AF
ZF
SF
OF
Control Flag
DF
IF
Set (1) Symbol
CY (carry)
PE (even parity)
AC (auxiliary carry)
ZR (zero)
NG (negative)
OV (overflow)
Clear (0) Symbol
NC (no carry)
PO (odd parity)
NA (no auxiliary carry)
NZ (nonzero)
PL (plus)
NV (no overflow)
DN (down)
EI (enable interrupts)
UP (up)
DI (disable interrupts)
Debug Program
7
• To step through the program, type T:
The first instruction is MOV AX, 4000h
-T
AX=4000 BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=0003 NV UP EI PL NZ NA PO NC
1A0A:0003 03C0
ADD AX, AX
Unchanged, since a
MOV doesn’t affect
the flags
Debug Program
8
• To step through the program, type T:
Next, ADD AX, AX
-T
AX=8000 BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=0005 OV UP EI NG NZ NA PE NC
1A0A:0005 83E8FF
SUB AX, -01
Debug Program
9
• To step through the program, type T:
Next, SUB AX, 0FFFFh
-T
AX=8001 BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=0008 NV UP EI NG NZ AC PO CY
1A0A:0008 F7D8
NEG AX
Debug Program
10
• To step through the program, type T:
Next, NEG AX
-T
AX=7FFF BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=000A NV UP EI PL NZ AC PE CY
1A0A:000A 40
INC AX
Debug Program
11
• To step through the program, type T:
Finally, INC AX
-T
AX=8000 BX=0000 CX=000F DX=0000 SP=0100 BP=0000 SI=0000 DI=0000
DS=19FA ES=19FA SS=1A0B CS=1A0A IP=000B OV UP EI NG NZ AC PE CY
1A0A:000B B44C
MOV AH, 4C
Debug Program
12
• To complete execution of the program, type G:
Program terminated normally
• To exit the DEBUG program, type Q:
-Q
c:\asm>
Debug Program
13

There are many other DEBUG commands, among them are:
 R{register}: to change the contents of a register.
 E: to change the contents of a memory location.
 D: to display memory contents byte by byte.
 U: to display the corresponding machine code.

Appendix E contains a detailed description of all DEBUG commands !!!
Debug Program
14