You are on page 1of 7

EXPERIMENT NO. 1 DEBUG PROGRAMMING I. Objectives: To introduce DEBUG program for debugging purposes.

. To apply the microprocessor concepts and assembly programming. II. Conceptual Framework: DEBUG is a program included in the MS-DOS and PC-DOS operating systems that allows the programmer to monitor programs execution closely for debugging purposes. Specifically, it can be used to examine and alter the contents of memory to enter and run programs, and to stop programs at certain points in order to check or even change data. II.A. Entering and exiting DEBUG To enter the DEBUG program, simply type its name at the DOS level: C:\ WINDOWS \ 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. II.B. 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. II.C. 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 -U <starting address> <starting address> <ending 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 DEBUG 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. II.D. 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 -D <start address> <start address> <end 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 -F <starting address> <starting address> <ending address> <data> <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 -E <address> <address> <data list>

For example, - E 100 John Smith. This example showed how to enter ASCII data, which can be enclosed in either single or double quotes. II.E. Additional DEBUG Data Manipulation commands M, the MOVE command. The move command is used to copy data from one location to another. The original location will remain unchanged. The syntax of this command is: - M <start address> <end address> <destination address> - M <start address> <L number of bytes> <destination address> C, the COMPARE command. The compare command is used to check two areas of memory and display bytes that contain different data. If the two blocks are identical, DEBUG will simply display the command prompt -, otherwise it will print all locations that were not identical. - C <start address> <end address> <compare address> - C <start address> <L number of bytes> <compare address> S, the SEARCH command. The search command is used to search a block of data for a specific data value. If the item is not found, DEBUG simply displays the command prompt . Otherwise, all locations where the data item was found will be displayed. The syntax is: - S <starting address> <ending address> <data> - S <starting address> <L number of bytes> <data> II.F. Hexarithmetic command The Hexarithmetic (H) command is like an on-line hex calculator that performs hex addition and subtraction. Its format is: -H <hex number 1> <hex number 2> 3

When this command is executed, DEBUG will display their sum followed by their difference. II.G. Procedure command The Procedure (P) has a syntax similar to trace command: -P <start address> <number of instructions>

It is used to execute a loop, call, interrupt or repeat string operation as if it were a single instruction instead of tracing through every instruction in that procedure. II.H. 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 <drivename:> <filename> <.extension name> After the code has been entered with N command, registers BX and CX must be set to contain the number of bytes to be saved. W, the WRITE command. The write command is used to save instructions unto 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

III. Materials / Equipment: o IBM PC/XT with an 8088 microprocessor computer o Program Diskette (which contains PC-DOS and DEBUG) IV. Procedure: 4.1 Command: R A. Examine the contents of the following registers: REGISTER CONTENTS IP CX AX DX B. Modify the contents of the following registers: 4

COMMAND

REGISTER AX CX IP C. Type in the command: R Illustrate the output:

CONTENTS

COMMAND

4.2 Command: A Assemble the given program at the starting offset address 100h: CS:0100 MOV AX, 1 MOV BX, 2 MOV CX, 3 ADD AX, BX ADD AX, CX INT 3 Command: ________________________________ Ending Address: ___________________________ 4.3 Command: U A. Unassemble the program assembled in 4.2: Command: _____________________________ B. What are the equivalent machine codes of the following instructions? Instruction Machine Code MOV AX, 01 MOV CX, 3 ADD AX, BX 4.4 Command: G A. Execute the program in 4.2: Command: _____________________________ B. What are the contents of the following registers? AX BX

CX

4.5 Command: T A. Trace the program in 4.2: 5

Command: _____________________________ B. 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 4.6 Command: D A. Illustrate the output after executing the following D commands: Command Output D 100 10F D CS:110 120 B. Type in the command: D No. of bytes displayed: _____________________________ Beginning Address: _____________________________ Ending Address: _____________________________ 4.7 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 CS:100 1FF 20 CS:100 CS:1FF - F 100 L20 00 FF 100 11F B. Fill the following blocks of memory with the specified data: Block of Memory Data Command 100 110 00 11F - 130 00, 01, 10, 11 (alternately) 4.8 Command: E A. Enter the data John Snith at the starting address 100h: Command: _____________________________ B. Modify the data John Snith to John Smith (ASCII code of m=6D) Command: _____________________________

4.9 Command: M, C, S 6

A. Move 20 bytes of data from 100h address to 200h: Command: _____________________________ B. Compare the 20 bytes of data between 100h and 200h addresses: Command: _____________________________ Output: _____________________________ C. Search the data FF in the following blocks of memory: Block of Memory Command 100 10F CS:100 CS:1FF 100 11F 4.10 Command: H A. Compute for the sum and difference between A5h and 25h. Command: _____________________________ Output: _____________________________ 4.11 Command: N, W, L A. Assemble the given program at starting address 100h: Command: _____________________________ CS:0100 MOV CX, 05 MOV BX, 0200 MOV AL, 0 ADD AL, [BX] INC BX DEC CX JNZ 0108 MOV [0205], AL INT 3 B. Name the file expt1.com and saved it in drive A:\ Command (Naming): _____________________________ Command (Saving): _____________________________ C. Exit from DEBUG and load the file that you saved. Command (Name): _____________________________ Command (Load): _____________________________ Note: You can also load a file by this format: DEBUG <filename>

Output

You might also like