Sunteți pe pagina 1din 5

Microprocessor and Assembly Language (CS330)

Laboratory Exercise 2
Objective:
To introduce System commands using DEBUG programming utility (at command
prompt using PC).

Description:
DEBUG is a program included in the MS-DOS and PC-DOS operating systems that
allows the programmer to monitor a program’s 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. Student will learn
 How to enter and exit DEBUG,
 How to assemble and unassembled a code
 How to observe machine code
 How to examine and alter the contents of registers and memory

Installing DOSBox and Mounting the Working Drive:


DOSBox is an emulator program which emulates an IBM PC compatible computer
running a DOS operating system. It is a free software written in C++ programming
language and distributed under the GNU General Public License.

Download and install the DOSBox.

Click the DOSBox icon, it will open a command window with a prompt Z:\>

Consider that the executable file “Debug.exe” is stored in the folder LAB in drive D
i.e., “D:\LAB\”. To access the file write the following command on Z:\> prompt

Z:\>Mount C D:\LAB and press Enter key

This command emulates drive C as your working drive.

Next, write the following command

Z:\> C: and press Enter key

This command will result in the following prompt

C:\ >

Entering and Exiting DEBUG:


To enter and exit the DEBUG, simply type its name at the DOS level:
C:\ > DEBUG and press Enter key

Department of Computer Science 6


Sir Syed University of Engineering & Technology
Microprocessor and Assembly Language (CS330)

NOTE:
 DEBUG is not case-sensitive.
 It is assumed in the above instruction that DEBUG program is on the drive C
 After enter key pressed, the DEBUG prompt “-“ will appear on the following
line.
To quit the DEBUG, type Q at the DEBUG prompt and enter

Q <return>
C:\>
System Commands:
The system commands can be divided into the following groups according to their
functions.
 Memory Management Commands.
 Assembler Commands.
 Program Execution Commands.
Note:
 Hexadecimal numerical system is used throughout the experiments
(unless otherwise specified).
 The suffix ‘H’ can be omitted.

Each command begins with a command letter followed by 1 to 3 operand parameters.


This lab will discuss memory management commands and assembler commands. The
program execution commands will be discussed later.

Memory Management Commands


C Compare the contents of two blocks of memory.
D Display the contents of memory.
E Edit (Write) data into memory.
F Fill the memory with a value.
M Move the contents of memory.
Command C: Compare the contents of two blocks of memory
Command syntax C<Range>, <Address>
 <Range> indicates the source area
 <Address> is the starting address of the target memory block.
 If any mismatch is found, the system displays both the source and target addressees
and their contents.
Command D: Display the contents of memory
Command syntax D<Range>
 It will display the contents of a specified memory location.
 The ASCII codes for this value will also displayed.
 <Range> tells the D command what range of memory to display.
 If range is not specified, then the default starting address is set to the location following
the last address used by a previous D command.
 It there is no previous D commands, then the default starting address is 0100:0000.
 The default length of display is 80H.

Department of Computer Science 7


Sir Syed University of Engineering & Technology
Microprocessor and Assembly Language (CS330)

Command F: Fill the memory with a value


Command syntax F<Range> <Series>
 It is used to change the contents of a block of memory to a certain sequence of values.
 The memory locations specified in <Range> are filled with the values specified in <series>.

Command E: Edit (Write) data into memory


Command syntax E<Address> <Series>
 It is used to write data into memory.
 When E command is used without a <series> parameter; the system displays the <address>
and its contents, a byte of data.
 The user then types in a new byte of data, (two hexadecimal digits), to replace it.
 If <CR> is pressed, the next address can be edited.
 Memory can be edited until <Q> is pressed to exit the E command.

Command M: Move the contents of memory


Command syntax M<Range>, <Address>
 It move the contents of a block of memory specified in <Range> from one place to
another.
 The starting address of the destination is specified in <Address>.

Command H: Calculate the sum and difference


Command syntax H<Value 1>,<Value 2>
 If the sum is greater than FFFF the carry is discarded.
 Only 16 bits (4 hexadecimal digits) of the result are displayed.
 If <Value 1> is smaller than <Value 2>, borrow is used to execute subtraction.
Figure 2.3 shows the H command.

Figure 2.3 H commands

Assembler Commands
The following letters stands for,
A Assemble a program.
U Disassemble a program

Command A: Assemble a program


Command syntax A [<Address>]
It is used to program with the 8088 assembly language as shown in Figure 2.1.

Department of Computer Science 8


Sir Syed University of Engineering & Technology
Microprocessor and Assembly Language (CS330)

Figure 2.1 Assembler Command

Command U: Disassemble a program


Command syntax U [<Range>]

 It is used to disassemble assembly language instructions into machine code.


 <Range> is used to select a block of memory to disassemble.
 If <Range> is not specified, then the system will start immediately after the final address
of the last U command.
 If no U command have been executed, the default starting address is CS: IP, which is set
to 0100:0000 after power-on.
 The default length is 20H.

Figure 2.2 shows the Disassemble command with start address, end addresses, and machine
code.

Figure 2.2 Disassemble Command

Activity- 1:
Do the following using Memory management commands and capture each screen using print
screen option.
- Display the memory contents starting from memory location 0100h
- Display the memory contents of first 10 bytes starting from memory location 0100h
- Fill the memory location starting from 0200h with your name and 3-digit Roll #
- Note the last offset (memory) value of the last digit of your roll #
- Move the block of memory where you filled your name and Roll # to the memory
location starting from 0400h
- Compare the two memory blocks (one starting from 0100h & the other from 0400h)
- Edit 2018-CS- to the memory block starting from 0400h before your Roll #
- Compare the two memory blocks (one starting from 0100h & the other from 0400h)
- Calculate the sum and difference of 75 and 34 using H command

Department of Computer Science 9


Sir Syed University of Engineering & Technology
Microprocessor and Assembly Language (CS330)

Activity- 2:
Assemble and Unassemble the following code and fill the following table .
Logical Address Opcode Assembly code Comments
MOV AX, 0200H ;

MOV BX, 0400H ;

ADD AX, BX ;

Activity- 3:
Give answers to the following questions after unassemble the code:

Why the values 0200H and 0400H are written as 0002 and 0004, in the opcode, respectively?

Write the number of bytes and the value of IP register taken by each instruction.

Department of Computer Science 10


Sir Syed University of Engineering & Technology

S-ar putea să vă placă și