You are on page 1of 12

Using Debug-I

OBJECTIVES: To study and use DEBUG utility. Monitor a programs execution for debugging purposes. Examine and alter register and memory contents. INTRODUCTION: Debug is part of Disk Operating System (DOS) which is used to enter an assembly language program into PC, execute the program, examine the results and debug any errors. In this lab you will be familiarized with debug environment and commands to examine or modify the MPUs internal registers. Before using debug make sure that you are in DOS shell. In Windows follow these steps:

1.

Start > Run > CMD (Press Enter)

2.

Type debug at the command prompt and record your observations. _____________________________________________________________________

3.

Type q at the appeared prompt to quit. _____________________________________________________________________

The first command we will use in debug is called Register command. Upon execution of register command the content of all the internal registers of MPUs are displayed on the screen. 4. After step 1, type r or R to view the register dump. First line: ___________________________________________________________ Second line: _________________________________________________________ Third line: ___________________________________________________________ 5. Write the contents of the general purpose registers in the first line. _____________________________________________________________________ 6. Write the contents of the segment registers. _____________________________________________________________________ Note: Dont try to change the contents of the segment registers. These have been set by the operating system. Modifying Register Contents: 7. Type r followed by a register name. E.g. Type -r ax What are the contents of AX? ____________________________________________________________________

Microprocessor & Assembly Language

Lab: 01

8.

Enter a new value for AX at the colon prompt. : 12AB Type r again to verify the contents of AX. What is the new value in the AX? _____________________________________________________________________

9.

Try these values and record your observations: -R DX DX 0000 : FF _____________________________________________________________________

-R DX DX 00FF : 12345 _____________________________________________________________________

-R DX DX 00FF : NAV _____________________________________________________________________

-R DH ____________________________________________________________________ Modifying Flags In addition to modify the internal register contents, debug can also be used to modify MPU flags. Notations used for displaying the status flags are given in table below:

FICT, BUITEMS

Microprocessor & Assembly Language


Flag OF DF IF SF ZF AF PF CF Meaning Overflow Direction Interrupt Sign Zero Auxiliary Carry Parity Carry Set OV DN EI NG ZR AC PE CY Reset NV UP DI PL NZ NA PO NC

Lab: 01

10. To show current flag status type: -R F Name the flags which are set: _____________________________________________________________________ To modify flags just type in new states of all flags separated by spaces and depress enter key. Note that the new flag states can be entered in any order. What will you enter to set Carry and Zero flag? _____________________________________________________________________ How would you use register command to set the parity flag to even parity? _____________________________________________________________________

CONCLUSION

What have you learnt in this session? _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________

FICT, BUITEMS

Microprocessor & Assembly Language

Lab: 02

Using Debug-

2
Lab

INTRODUCTION: In the previous lab we were dealing with internal registers of MPU. This lab is focused on examining and modifying the memory contents. There are six commands which are used to examine or modify the contents of storage locations in memory. These commands are Dump, Enter, Fill, Move, Compare and Search. In this lab we will discuss Dump command. The DUMP Command: The DUMP (D) command allows us to examine the contents of a memory location or a block of consecutive memory locations. On the debug prompt, type:

D This will cause 128 consecutive bytes starting at offset 0100H from the current value in DS to be displayed. Note that 16 bytes of data are displayed per line, and only the address of the first byte is shown at the left. What is the Physical Address of the first location? ____________________________________________________________________________ What type of information is displayed in the third column? ____________________________________________________________________________ The DUMP command can also be issued by specifying the starting address of the memory block. As we have discussed in class that physical address is combination of base address stored in one of segment registers and offset address stored in IP, DI, SI, BP etc. to dump the memory contents you can enter: D DS: 100 or: D 1342: 100 or: D 100 Note that if no segment base register is specified, then data segment will be taken as default.

What happens if D is entered repeatedly? ____________________________________________________________________________

FICT, BUITEMS

Microprocessor & Assembly Language


You can also specify the size of block by providing a third parameter in DUMP command. For example:

Lab: 02

D DS: 200 201

What is result of above command? __________________________________________________________ What would be the command to display the contents of 32 bytes of memory located at offset 0300H in the current data segment? __________________________________________________________ Is it possible that the memory contents of segments other than data segment (like code, stack etc) can be displayed? If yes then what would the parameters? __________________________________________________________ __________________________________________________________

Name: ___________________________

Roll No.:_________________________

Date: ____________________________

Signature of Instructor: ______________

FICT, BUITEMS Page 5 of 12

Microprocessor & Assembly Language

Lab: 03

Using Debug-II

3
Lab
[List] AA AA AA AA AA 104

The ENTER Command:Enter command can be used to modify the memory contents. The format of Enter command is given below:

[Address]

The address part of the Enter command is entered in the same manner as that of Dump command. The List that follows the address is the data that gets loaded into memory. For example, following command will load five consecutive bytes to memory locations starting at address DS: 100 with the value AA?

DS: 100

You can verify the results of above command by issuing Dump command:

DS: 100

Note that we have also given the ending address of the memory block which is to be dumped.Instead of loading a list of data into memory, we can also use Enter command to modify the memory locations one by one. This can be done if you dont provide the List in Enter command as shown below:

DS: 200

(enter)

Above command causes the value at DS: 200 to be displayed. Note that the cursor will be blinking at the end of the data value. At this point you can either enter new value which will replace the existing data or you can depress the return key to terminate the Enter command. Doing this will not affect the existing data in memory.

After executing Enter command without providing the List, depress Space key. What will happen?

____________________________________________________________________________ FICT, BUITEMS

Microprocessor & Assembly Language

Lab: 03

Start a data entry sequence by examining the contents of address DS: 100 and then, without entering new data, depress the key. What happens?

In addition to above methods of modifying memory contents, you can also enter ASCII data using Enter command.

DS: 300

YOUR_NAME

The above command will cause the ASCII data for letters of your name to be stored in memory. The FILL Command: Fill command is used to modify the contents of a large block of memory. It would be time consuming to use Enter command to modify a large memory block since you have to modify each location one by one. To clarify this point, lets assume that you have to enter the value BB at fifty consecutive memory locations starting at address DS: 400. If you choose Enter command for this purpose then you will be entering BB fifty times. Fortunately Fill command is available in Debug to help us. The format of Fill command is shown below:

[Starting Address]

[Ending Address]

[List]

The above problem can be solved easily using Fill command:

400

431

BB

You can try Enter command to notice the difference between Fill and Enter commands. The MOVE Command:In debug, the Move command signifies a Copy-Paste operation. Move command can be used to copy a block of data from memory to another part. The format of Move command is given below:

[Starting Address]

[Ending Address]

[Destination Address]

Fill each storage location in the block of memory from addresses DS: 600 through DS: 61F with the value 11. Then copy this block of data to a destination block starting at DS: 660. Verify that the block move is correctly done.

FICT, BUITEMS

Microprocessor & Assembly Language

Lab: 03

The COMPARE Command: Sometime it is required to compare two blocks of memory to determine if they are same or not. Such type of comparison can be done by using Compare command. The format of Compare command is given below:

[Starting Address]

[Ending Address]

[Destination Address]

For example, to verify the correct movement of block of data we moved previously, following command sequence can be issued in Debug:

600

61F

660

During the execution of above command, the contents of memory location 600 will be compared to 660, 601 to 661 and so on. Each time unequal elements are found, the address and contents of that byte in both blocks will be displayed. No address will be displayed if the two data are same. You can enter a destination address other than 660 in above command to understand this point. The Search Command:The Search command is used to scan through a block of data in memory to determine whether or not it contains specific value. The general form of Search command is given below:

[Starting Address]

[Ending Address]

[List]

To understand the use of Search command, type following command sequence:

F S

100 100

16F 17F

22 33

33

How many memory locations contained 33?

What are the addresses?

FICT, BUITEMS

Microprocessor & Assembly Language

Lab: 03

Hexadecimal Addition and Subtraction:Debug has ability to add and subtract hexadecimal numbers. Both operations are performed with a single command known as the Hexadecimal command. The format of Hexadecimal command is shown below:

[Num 1]

[Num 2]

When executed, both sum and differences of Num 1 and Num 2 are displayed on the screen, sum being displayed first.

Using Hexadecimal command, write down the command sequence you will issue to calculate the Physical Address of next instruction to be executed? ______________________________________________________________________

Find the negative of 6H using Hexadecimal command. ______________________________________________________________________

EXERCIES:
Write a sequence of commands that will fill the first six storage locations starting at address CS: 100 with 11, the second six with 22, the third six with 33, the fourth six with 44, and the fifth six with 55; change the contents of storage locations CS: 105 and CS: 113 to FF; display the first 30 bytes of memory starting at CS: 100; and then use a search command on this 30 byte block of memory to find those storage locations that contain FF.

Name: ___________________________ Date: ____________________________

Roll No.:_________________________ Signature of Instructor: ______________

FICT, BUITEMS

Microprocessor & Assembly Language

Lab: 04

Using Debug-IV
Entering and Running Programs Use Assemble command A <starting address> to enter Assembly Language instructions into memory. Starting address will be the offset into the code segment by default. Type: -A 100 0B12:0100 0B12:0103 0B12:0106 0B12:0109 0B12:010B 0B12:010D MOV AX,1 MOV BX,2 MOV CX,3 ADD AX,BX ADD AX,BX INT 3

4
Lab

Note: Do not assemble beginning at an offset lower than 0100, as the first 256 bytes (100H) are reserved by DOS.Difference between Debug programming and Assembly programming are that numbers are hexadecimal by default in Debug, whereas in Assembly an H had to be appended at the end of a number to enter it in hexadecimal To view the machine code, use the Unassemble command U in any one of the following ways:

-U <starting address> -U <starting address> <ending address> -U <starting address> L <number of bytes > -U <RETURN> To view the 32 bytes beginning at CS:IP

Microprocessor & Assembly Language

Lab: 04

Type the following and give your observations: -U 100 10D _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ To execute the instructions, use the Go command G, as: -G <=staring address> <stop address(es)>

If no addresses are given then execution starts at CS:IP and continues till a breakpoint e.g. INT 3, is reached.

-R ___________________________________________________________________

_____________________________________________________________________ _____________________________________________________________________ Then type:

-G

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________

To trace through the execution of a program, use the trace command T as: -T <=starting address> <number of instructions>

Microprocessor & Assembly Language

Lab: 04

Type:

-T=100 2

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________

-T 3

_____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________

CONCLUSION

What have you learnt in this session? _____________________________________________________________________ _____________________________________________________________________ _____________________________________________________________________

Name: ___________________________ Date: ____________________________

Roll No.:_________________________ Signature of Instructor: ______________

You might also like