140 likes | 251 Views
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. Outline. Introduction A demo program Using the debug program. Introduction.
E N D
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
Outline • Introduction • A demo program • Using the debug program Debug Program
Introduction • 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
A Demo Program 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
Using the Debug Program • 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
Using the Debug Program (R) • 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=0000NV UP EI PL NZNA 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
DEBUG Flags Symbols Status Flag Set (1) Symbol Clear (0) Symbol CF CY (carry) NC (no carry) PF PE (even parity) PO (odd parity) AF AC (auxiliary carry) NA (no auxiliary carry) ZF ZR (zero) NZ (nonzero) SF NG (negative) PL (plus) OF OV (overflow) NV (no overflow) Control Flag DF DN (down) UP (up) IF EI (enable interrupts) DI (disable interrupts) Debug Program
Using the DEBUG Program (T) --1 • 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=0003NV UP EI PL NZ NA PO NC 1A0A:0003 03C0 ADD AX, AX Unchanged, since a MOV doesn’t affect the flags Debug Program
Using the DEBUG Program (T) --2 • 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=0005OV UP EI NG NZ NA PE NC 1A0A:0005 83E8FF SUB AX, -01 Debug Program
Using the DEBUG Program (T) -- 3 • 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=0008NV UP EI NG NZ AC PO CY 1A0A:0008 F7D8 NEG AX Debug Program
Using the DEBUG Program (T) -- 4 • 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=000ANV UP EI PL NZ AC PE CY 1A0A:000A 40 INC AX Debug Program
Using the DEBUG Program (T) -- 5 • 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=000BOV UP EI NG NZ AC PE CY 1A0A:000B B44C MOV AH, 4C Debug Program
Using the DEBUG Program (G – Q) • To complete execution of the program, type G: Program terminated normally • To exit the DEBUG program, type Q: -Q c:\asm> Debug Program
Using the DEBUG Program • 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