You are on page 1of 13

QUEZON CITY POLYTECHNIC UNIVERSITY

673 Quirino Highway San Bartolome, Novaliches , Quezon City


BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Laboratory Activity #2:

Student Name: ____________________________ Section: _______ Score: ____

The DEBUG prompt is a hyphen or an underscore; commands are written after this prompt

 Click on “Start” Menu on the windows 98 desktop Environment to get the DEBUG Program.
 On the pull down menu, select “Programs”
 On the next menu, select the MS-DOS Prompt or Command Prompt, you should get the DOS prompt
line “C:\Windows>”
 Type DEBUG on the Windows Prompt Line and the Debug Prompt “-“should appear.
 Type in “?” for listing of DEBUG commands you can enter

DEBUG Commands

R Command -> This means REGISTER Command

Format : R <Register Name>

Example -R AX

Details

Displays the content of the Register AX. Its execution causes the current value in the AX to be displayed. If,
for instance, the accumulator contains 0000 this command displays:

AX 0000
:

If the value is to be unchanged, press the Enter key on the keyboard, otherwise enter the new value after
the Semicolon (:) then press Enter Key again

Register Mnemonics for R Command

Symbol Register
AX Accumulator Register
BX Base Register
CX Count Register
DX Data Register
SI Source Index Register
DI Destination Index Register
SP Stack Pointer Register
BP Base Pointer Register
CS Code Segment Register
DS Data Segment Register
SS Stack Segment Register
ES Extra Segment Register
F Flag Register

Notations used for displaying Flag Status:

FLAG MEANING SET RESET


OF Overflow OV NV
DF Direction DN UP
IF Interrupt EI DI
SF Sign NG PL
ZF Zero ZR NZ
AF Auxiliary Carry AC NA
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

PF Parity PE PO
CF Carry CY NC

Examples:

1. Issue Commands to the debugger on the PC that will cause the value in BX to be modified to FF00H
and then verify that this value exist in BX.

To modify the contents of BX


-R BX (Enter Key)
BX 0000
:FF00 (Enter Key)
Blinking Cursor

To verify the contents of BX


-R BX (Enter Key)
BX FF00
:_ (Enter Key)
Blinking Cursor
2. Use the Register Command to set the parity flag to even parity. Verify that the flag has been
changed.

To modify the parity


-R F (Enter Key)
NV UP EI PL NZ NA PO NC – PE (Enter Key)

To verify the modification


-R F (Enter Key)
NV UP EI PL NZ NA PO NC – (Enter Key)

D Command -> means DUMP Command, examines the contents of a memory location or a block of consecutive
memory location

Format
D <Address>

The value of the address entered is automatically referred to the current value in the Data Segment
(DS) Register.

For all memory Dumps, an ASCII version of the memory data is displayed to the right of the hexadecimal
data.

Repeated executions of the D Command display, iteratively, the next 128 bytes of memory locations

To display a specific range of data use the command:

D <Start Address> <End Address>

To examine the data that are stored in the Code Segment (CS), Stack Segment (SS), or Extra Segment
(ES), use the appropriate segment register name in the command.

Examples:

1. To examine two (2) bytes of data that are at offset equal to 0200H and 0201H in the current Data
Segment (DS).
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

-D DS:0200 0201 (Enter Key)

2. Issue a dump command that will display the 32 bytes of memory locations that are located at offset
0300H to 031FH in the current Data Segment (DS).

-D 0300 031F (Enter Key)

3. The command needs to dump the values in the first 16 bytes of the current Code Segment (CS) and
Extra Segment (ES) are:

-D CS:0000 000F (Enter Key)


-D EX:0000 000F (Enter Key)

4. Use the dump command to examine the 16 bytes of memory just below the top of the Stack.

The top of the Stack is defined by the contents of the SS (Stack Segment) and SP Registers (SS:SP). If
the SP was initialized to FFEE, when debug was loaded, the 16 bytes of interest reside at offset FFEE
through FFFD from the current value in Stack Segment (SS). This part of the stack is examined with
the command:

-D SSFFEE FFFD (Enter Key)

E Command -> Enter Command modifies the data stored in specific memory locations.

Format:

E <Address> <List>

The address part of command E follows the same notational semantics as in the D command – if no segment
name is included with the offset, the DS Register is assumed.

The list that follows the address is the data values that are loaded in the specific memory locations.

Issuing an E command with an address but no data displays the contents of the addressed storage location.
However, the programmer may opt to do one of these three actions:

1. Press the Enter Key: This action terminated the Enter Command without modifying the contents of the
memory location.
2. Press the Space Bar: This action causes the contents of the next consecutive memory location to be
displayed.
3. Enter a new Values of Data: this modifies the contents of the specified memory location and allows the
programmer to continue with the next consecutive memory location (by pressing the spacebar) or to
terminate the Enter Command (by pressing the Return/Enter key).

The ENTER command can also be used to enter ASCII data – this is done by enclosing the data enter in quotation
marks (single or double quotation marks can be used).

Examples:

1. The command that loads five consecutive byte-wide memory locations that start at address DS:100 with
the value FF is:

-E DS:0100 FF FF FF FF FF (Press Enter Key)


QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

2. The command

-E DS:0200 “ASCII” (Press Enter Key)

Causes the ASCII data for the letters A, S, C, I, and I to be stored in the memory locations with addresses
DS:0200, DS:0201, DS:0202, DS: 0203, DS:0204 respectively.

F Command -> Fill Command > stores a block of consecutive memory locations with the same data.

Format:

F <Starting Address> <Ending Address> List

The starting address and the ending address specify the block of storage location in memory.

Examples:

1. The command

-F 0100 011F 22 (Press Enter Key)

Causes a 32-byte locations in the range in the DS:0100 through DS:011F to be loaded with 22H.

2. Initialize all storage locations in the block of memory from DS:0120 through DS:013F with the values 33H
and the block of storage locations from DS:0140 through DS:015F with the value 44H. Verify that the
contents of these ranges of memory are correctly modified.

The Initialization operations can be done with the FILL Commands that follow:

-F 0120 013F 33 (Press Enter Key)


-F 0140 015F 44 (Press Enter Key)

They are verified by the Dump Command:

-D 0120 015F (Press Enter Key)

A Command -> ASSEMBLE Command – Assembles the Instructions of a program, one after the other, and stores
them in a specific memory location.

Format:

A <Starting Address>

The parameter starting address refers to the address at which the machine code of the first instruction of the
program is to be stored.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Examples:

1. To assemble the instruction ADD [BX + SI + 1234], AX and store its machine code in the memory starting
at address CS:0100, the command entry is:

-A CS:0100 (Press Enter Key)

Assuming that the code segment (CS) register is initialized to 0CDEH, the response to this command
input is the display of the starting address in the form:

0CDEH:0100_

The instruction to be assembled is typed in following this address and when the enter key is pressed; the
instruction is assembled into machine code. It is, thus, stored in the memory and the starting address of
the next instruction is displayed. At this point, either the next instruction is entered or the enter key is
pressed to terminate the ASSEMBLE command.

2. Assume that the program listed below is to be stored in the memory starting at address CS:0200. The
assembler is invoked with the command:

-A CS:0200 (Press Enter Key)

Assuming that the Code Segment (CS) register contains the value of 0CDEH, this gives the response:

0CDE:0200_

The instruction of the program are types in as follows:

0CDE:0200 MOV AX, 1020 (Press Enter Key)


0CDE:0203 MOV DS, AX (Press Enter Key)
0CDE:0205 MOV SI, 0100 (Press Enter Key)
0CDE:0208 MOV DI, 0120 (Press Enter Key)
0CDE:020B MOV CX, 0010 (Press Enter Key)
0CDE:020E MOV AH, [SI] (Press Enter Key)
0CDE:0210 MOV [DI], AH (Press Enter Key)
0CDE:0212 INC SI (Press Enter Key)
0CDE:0213 INC DI (Press Enter Key)
0CDE:0214 DEC CX (Press Enter Key)
0CDE:0215 JNZ 020E (Press Enter Key)
0CDE:0217 NOP (Press Enter Key)
0CDE:0218 (Press Enter Key)

G Command -> Go Command – provides the option for executing the entire program or of executing the
program in several segments of instructions by using breakpoints.

Format:

G=<Starting Address> <Breakpoint Address>

The starting address is the address of the instruction at which execution is to begin.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

The breakpoint address is the address of the end of the program segment (that is, the address of the instruction
at which the execution is to stop).

The breakpoint address specified must correspond to the first byte of an instruction.

A list of up to ten (10) breakpoint addresses can be supplied with the command.

Examples:

1. The command

-G=CS:0200 0217 (Press Enter Key)

Loads the IP Register with 0200H, sets a breakpoint at address CS:0217, and then begins
program execution at address CS:0200. Instruction execution proceeds until the address CS:0217
is accessed. When the breakpoint address is reached, program execution is terminated, the
complete internal status of 8086 is displayed, the control is returned to DEBUG.

2. The Command

-G:CS:0100 (Press Enter Key)

Executes a program that starts at offset 0100H in the current Code Segment (CS). This command
causes the program to run to completion. If the Code Segment and IP is already initialized with
the correct values, the command:

-G (Press Enter Key)

Will execute program to completion.

T Command -> TRACE – Steps through the program by executing one or more instruction at a time.

This command allows the programmer with the ability to execute one instruction at a time (this operation is
known as single-stepping the program).

The single-step operation displays the contents of the registers or specified memory locations before and after
the execution of each instruction.

Format:

T = <address> <number>

If an instruction is not specified, one instruction is executed at a time.

Examples:
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

1. The Command

-T = CS:0100 (Press Enter Key)

Causes the instruction starting at address CS:0100 to be executed. At the completion of the
instruction’s execution, the complete state of the internal registers is automatically displayed. At
this point, other debug commands may be issued.

2. The Command

-T (Press Enter Key)

Executes the instruction pointed to by the current values of the CS and IP (CS:IP) registers. This is
the form of the TRACE command used to execute the next instruction.

3. The command

-T = CS:0100 3 (Press Enter Key)

Traces through 3 (three) instructions. Again, the internal state of the 8086 is displayed after
each instruction is executed.

1. Exercises

 Issue a dump command that will display the 64 bytes of memory locations that are located at offsets
0500H through 053FH in the current data Segment. Observe the memory data display to the right of the
hexadecimal Data.

 Execute the command below:

-E DS:0500 ‘Information and Communications Technology (ICT)’

 Repeat first Step and observe the memory data displayed to the right.

 Initialize all storage locations in the block of memory from DS:0500 through CS:051F with the value 44H.
Verify that the contents of these ranges of memory are correctly modified.

 Assume that the program listed below is to be stored in the memory starting at address CS:0500.
Assemble the program below.

MOV AX, 0500


MOV DS, AX
MOV SI, 0100
MOV DI, 0120
MOV CX, 0020
MOV AL, [SI]
MOV DI, [AL]
INC SI
INC DI
DEC CX
JNZ 050E
NOP
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

 Execute the Program.

 Trace the program and observe the contents of the registers and the memory locations used.

Note:

If the WIN98 MS-DOS Environment cannot be installed in a 64-Bit Operating Machine you can skip this
Laboratory Activity and proceed with the EMU8086 Emulator program provided.

Laboratory Work:

1. Start Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.

2. Then you have this window.

3. Here’s the example program and explanation the discussion.

4. Input the assembly codes in the code window.

ORG 100h ; just a directive to make a simple .com file

MOV AX, 1001_1111b


MOV BX, AX
MOV CX, 16Eh
MOV DX, 17Eh
MOV [BX], AX, DX
MOV DS, BX, AX
MOV SI, DX, CX
MOV SS, SI
MOV BP, 1001_1010b
MOV DI, '8'
MOV AL, '!'
INT 10h
RET

5. Compile the Code by clicking the Compile button.


QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Note: Two (2) windows will appear upon clicking Compile button.

Window 1
Tells you about the passes that the compiler has made in order to create machine code for this assembly language code.

Window 2
Tells you about the name of the executable or binary file created into a location in your drive.

6. After Saving the binary/executable file, this window will appear.


QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

Window 3
Tells you about the details and option whether to run the binary or executable file or view details of compilation and or use
external debug.exe program, command prompt window, or the run command.

7. Click Run button instead to view the output in a separate window. And it should look like this:

Window 4
Let’s stay focus on the Emulator window.

8. By Clicking the Source Code Window line by line:

@ Line 3: MOV AX, 1001_1111b => 009F

On the Left side of the screen you will see the Emulator Window showing highlighted
memory address, together with the values you see in the left side pane for the Registers and at
the right-side of the window, the instruction as executed by EMU8086/8088 Emulator.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

In the middle of the dialog form, you will see the Memory Address being listed together
with the Hexadecimal Value (2 nd Column), and the ASCI Decimal Value (3 rd Column).
Therefore the initial value of AX (Accumulator Register) is set to 0009Fh. However, at the
Registers Pane on the left the from, the Value of AX Register is 0021h. That is because, the
initial value of AX at the end of the program has been overwritten by instruction code MOV AL,
021h, which sets the Lower chamber of AX Register to 21 and Higher chamber of AX Register
to 00.

You will also notice that there were three(3) memory addresses highlighted like the following:
07100, 07101, 07102, this means that the start of the program begins with the Segment
Address 0700 * 10 + 100 (program directive – ORG 100h) which gives a value 7100 as the
Base Address.

7100 Memory Address is the starting point of the program, and since the instruction
gives us MOV AX, 1001_1111b which in by term of hexadecimal the return value is 009F, the
upper chamber of the Register for AX will be the highest memory address (AH) 7102
containing the 00 value and (LH) 7101 by 9F. Since the instruction did not use another Pointer
Register Reference, 7100 became the temporary address reference, holding values for the
Memory Manager Unit.

@ Line 4: MOV BX, AX => 009F (D88B)

Memory Addresses 7103, and 7104 will be the location of the instruction MOV BX, AX. From
here you will notice that there were only two highlighted memory addresses, and hexadecimal
value contents for BH (Base Register Higher Chamber) = D8, and BL (Base Register Lower
Chamber) = 8B. This is because there were two(2) register addresses involved in the
instruction code and there’s no need for compiler/emulator to create a temporary pointer
register. This will copy the contents of AX moving the data to new register location BX. The
result of the copy will overwrite the previous values of BH and BL, acquiring the data from AX
= D88B to the new value 009F (BH:00; BL:9F).

@ Line 5: MOV CX, 16Eh => 016E

As based from Line 3, assembly code instruction, that same as applied in the execution. 7107
as the CH = 01, 7106 as CL = 6E and 7105 as the temporary pointer register. You will notice
that the value of CX = 016E has never change in the entire program, since it has never been
accessed until the program termination RET. The purpose of setting-up this instruction code is
for us to understand, that CX registers contains the same operations of storing, retrieving, and
moving of data from CPU Count Registers to Memory Registers.
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

@ Line 6: MOV DX, 17Eh => 017E

From line 5 as the same process goes, it only matters that, this time, it will use the Data
Registers intead. The values taken is in hexadecimal value and that it is transalated to have
DH=01 @ 710A; DL=7E @ 7109; and that DX=017E.

@ Line 7: MOV [BX], AX, DX => 0789

On this line, you will notice that the BX Base Register has a bracket, and this means that, this
address is sent directly to the Memory Register (and not considered to be a CPU Register), so,
the addressing notation as pointed out, should be two(2)-address notation to consider namely,
AX, DX. This would lead us to the same idea at Line 4, that, there will only be two(2)
addresseable memories to be allocated for the instruction. Having its [BH] = 07 – 710C and
[BL] = 89 – 710B; and [BX] = 0789, and the reason why on the registers pane, the value of BX
for BH and BL is not updated is because the instruction has been transferred to the Main
Memory and that is not catered by the CPU Registers. Also, take note that only BX registers
can be sent in the main memory and not the other registers you can see in the Registers Pane.

@ Line 8: MOV DS, BX, AX => DB8E (009F)

This line is definitely a three(3)-address notation, and similarly to the two-address notation,
since they are already two or more than two involved register addresses. The addreassable
memory locations to be addressed will be 710E and 710D, but, the DS (Data Segment)
Register does not have a High and Low chambers and that the initial value upon the execution
is DB8E, and overwritten as the compiler steps out from the line of execution updating the
values of DS to the recent value of BX = 009F.

Take note, that AX is used as a temporary register, and the only register valid for transfer is
BX.

@ Line 9: MOV SI, DX, CX => 8BF2 (017E)

Same goes from line 8, but this time SI (Source Index) Register is being used.

@ Line 10: MOV SS, SI => D68E (017E)

The SI, DI, SS, SP, BP, DS, ES, IP, and CS does not have Higher and Lower Chambers not
like general purpoe registers like AX, BX, CX, DX. So, the addressable memory locations will
only be two(2). Instruction line 10 will be at 7112 – D6 and 7111 – 8E => D68E. This
instruction will acquire recent value of SI = 017E.

@ Line 11: MOV BP, 1001_10101b => 009A

Base Pointer (BP) has 3(three) addressable memory locations, since there are pointers
needed to temporarily place a value of reference to an instruction. 7115 is used to store 00
QUEZON CITY POLYTECHNIC UNIVERSITY
673 Quirino Highway San Bartolome, Novaliches , Quezon City
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY DEPARTMENT

value just like general purpose registers do, 7114 for 9A => hexadecimal value for
1001_10101b, and the temporary pointer regsiter on 7113 which contains the value BD.

@ Line 12: MOV DI, ‘8’ => 0038

Same as the Base Pointer (BP), the Destination Index (DI) also has 3(three) addressable
memory locations, since there are pointers needed to temporarily place a value of reference to
an instruction. 7118 is used to store 00 value just like general purpose registers do, 7117 for
38 => hexadecimal value for 0011_1000 binary equivalent of ‘8’, and the temporary pointer
regsiter on 7116 which contains the value BF.

@ Line 12: MOV AL, ‘!’ => 0021

This will Overwrite the recent value of AX=009F to the new value ‘!’ on the ASCII code decimal
equivalent to 33 => 0010_0001b at hexadecimal value 21 at lower chamber. AX new value will
be 0021; AH = 00; AL = 21.

@ Line 12: INT 10h

INT (interrupt instruction), and 10h is an interrupt used for sub function of 0Eh, in which it
receives ASCII code characters to be printed in the AL register. Example is the “Hello, World!”
program.

@ Line 13: RET

Program termination and returning back to O.S. for control.

You might also like