You are on page 1of 14

University Of Dohuk Year 2021-2022/S2

College Of Engineering 2nd Year


ECE Department Microprocessor LAB1
EXPERMINT #6

Downloading, Debugging and Running the Assembled Program

I- Objective:

The objective of this experiment is to familiarize the students with microprocessor trainer kit MTS-
86C and loading some simple programs in the kit. There are two ways to download the machine code to the
RAM of MTS86, debugging and running this program through a MTS86 keypad or through a PC. This
experiment is emphasizing on the both methods.

II- Introduction: MTS-86C:


In our laboratory we shall study via 8086 kit MTS-86C. It a kit with I/O facility and built in interfacing devices
such as 8255, 8251, 8259, 8253, 8254 etc.

A- Downloading Program into MTS86 :

You can enter the machine code directly to the specified memory address by using the MTS86 Keypad.
To do this, you must deduce the machine code first. The machine code can be found, after the program is
assembled by using MASM program, in the file *.LST. For example, the list file of the LED.ASM is
shown below. The machine code is listed at the second column.

1
====================== LED.LST ===================================

Offset Machine Label Assembly Code Comments


Address Code

0000 BC 4000 START: MOV SP,4000H ; Setup stack pointer


0003 B0 90 MOV AL,90H ; Setup control word register
0005 BA 3FD6 MOV DX,CNT3 ; Setup output port
0008 EE OUT DX,AL ; Output data
0009 B0 FF MOV AL,0FFH ; Setup output data
000B BA 3FD2 MOV DX,BPORT3 ;Setup output port
000E EE OUT DX,AL ;Output data to portB
000F F4 HLT ;
0010 CODE ENDS

========================================================================

Rearrange the machine code so that they can be saved to a specified memory address in MTS86. Note
that if the code length is 2 BYTE ( 1 WORD), put the lower Byte first, as shown below

BC 00 40 BO 90 BA D6 3F EE B0 FF BA D2 3E EE F4

Turn on the power of MTS86 and following the steps shown below to input the machine code at
address (0100:0000) which equivalent to( 01000h) of physical address.

RESET MTS-86C SYSTEM RESET


K&H MFG
0 Examine Byte Examine Byte Command
EB/AX _ To specify a starting address
inside SRAM
1 Seg. Offs Data Enter Segment Address 0100
ER/BX 0000:0001_
0/ Seg. Offs Data Enter Segment Address 0010
EB/AX 0000:0010_
0 Seg. Offs Data Enter Segment Address 0100
EB/Ax 0000:0100_
: Seg. Offs Data Segment/ Offset Separator
0000:0100
0 Seg. Offs Data Enter Offset Address 0000
EB/AX 0100:0100_
, Seg. Offs Data Show Memory Data at
0100:0000 xx_ 0100:0000
B Seg. Offs Data Modify Memory Data BC at
/ES 0100:0000 0B 0100:0000
C Seg. Offs Data Modify Memory Data BC at
/IP 0100:0000 BC (0100:0000)

2
, Seg. Offs Data Show Memory Data at
0100:0001 xx (0100:0001)
0 Seg. Offs Data Modify memory Data 00 at
EB/AX 0100:0001 00 ( 0100:0001)
0 Seg. Offs Data
EB/AX 0100:0001 00
, Seg. Offs Data
0100:0002 xx
4 Seg. Offs Data Modify Byte to 40 at
IB/SP 0100:0002 04 (0100:0002)
0 Seg. Offs Data
EB/AX 0100:0002 40
, Seg. Offs Data Show Memory Data at
0100:0003 xx (0100:0003)
I
I
I
I
REAPTING KEYING THE MACHINE CODE FROM ADDRESS (01000:0004) TO (01000:000E).

, Seg. Offs Data Show Memory Data at


0100:000F xx (0100:000F)
F Seg. Offs Data Modify memory Data F4 at
0100:000F 0F ( 0100:0001)
4 Seg. Offs Data
IB/SP 0100:000F F4
, Seg. Offs Data
0100:0002 xx
4 Seg. Offs Data Modify Byte to 40 at
IB/SP 0100:0002 04 (0100:0002)
. MTS-86C > INPUT Command Termination
_ Prompt

3
B – Running the program

We have enter the machine code with starting address is located at (0100:0000). So now the program
is ready to execute by using GO Command.

RESET MTS-86C SYSTEM RESET


K&H MFG
2 Seg. Offs Data GO Command
GO/CX 0000:0000 XX GO
1 Seg. Offs Data Enter Segment Address 0100
ER/BX 0000:0001_ XX GO
0/ Seg. Offs Data Enter Segment Address 0100
EB/AX 0000:0010_ XX GO
0 Seg. Offs Data Enter Segment Address 0100
EB/Ax 0000:0100_ XX GO
: Seg. Offs Data Segment/ Offset Separator
0000:0100 XX GO
0 Seg. Offs Data Enter Offset Address 0000
EB/AX 0100:0000 XX GO_
. MTS_86C > INPUT Command Termination/
_ Prompt

.
After pressing the command termination key [ ], you suppose to see 8 LEDs on MTS86C are ON. If
the led LEDs are not ON, it might because (1) the machine code you input to the specified memory address is
incorrect or (2) you specify a wrong starting address for execution.

Exercise1:
1- Re-enter the above program with starting address (0200:0200), then execute it
from the new starting address. Record your observation.
2- Change the content of memory location 0009 to be 55h.and the executethe
Program again. What do you observe? Give your interpretation.

III-Connecting MTS-86C to PC and loading program to it:


1- To connect MTS-86C to a PC, connect serial port of the extended cord supplied to MTS-86C. Connect
the COM1 type end to COM1 port of PC. Switch on the module MTS-86C.
2- Go to start>program files>accessories>communications>Hyper Terminal
3- Select COM1 as port.
4- Click ok tab. Select bit rate to be 19200.
5- Mark flow control as (Xon/Xoff)
6- Press any key (between A-F) to make a communication between MTS-86C and PC.

4
A-Writing Code and making hex file:
1. 8086 cannot take a simple written text file. It takes hex files. So an text file needs to be converted to
hex file. This is done in following steps.
2. Write your code in a notepad file with necessary instructions.
3- Save the file as p1.asm (for example) in the folder named up in C drive.
4- Go to command prompt window.
5- You can observe that execution has begun.
6- Give bin file name as p1.bin.
7- Press Enter when asked for address.
8- Your hex file is created. For checking you can go to up folder and fine out newly created file p1.hex.

5
B- Assembling program:
This section introduce you how to convert an assembly program to machine code. There are two steps
to obtain the machine code, editing the source code and assembling the source code.
To edit the source program, simply edit it under any text editor, such NOTEPAD, MICROSOFT
word or DOS editor. We are going to use DOS editor in this experiment. BE SURE that the file is saved with
the extension of [.ASM]. The source program is an example of lighting up all of the LEDs in MTS-86C
shown in Fig# 1.1A and Fig 1.1B

Fig # 1.1A

Fig 1.1B

6
The following steps is to convert the source assembly program [ LED.ASM] to machine code
[ LED.HEX].
STEP1: Launch the DOS command Prompt
STEP2: Edit your source program
STEP3: Save the edited program with the extension [ . ASM]
STEP4: Exit from DOS editor
STEP5: Enter [ V LED] as shown below

NOTE: (DO NOT Enter [ V LED.ASM] , this action may damage your assembled code).

Fig #1.2

STEP6: After press [ ENTER], the batch file will ask you to input the binary file, as shown below in
Fig # 1.3

STEP7: Enter [ LED.bin] and press [ ENTER] twice. The hex file [LED.HEX] will generated automatically
in the same folder where the assembled program located.

Fig # 1.3

7
C- Downloading the program by PC:
The Exp#1 introduced you how to download the machine code to the MTS-86C by keypad. Now, this
experiment you will learn how to download the machine code to the MTS-86C by using the PC. The steps
are shown below.

1- Turn on the MTS-86C


2- Connect the RS232C-1 port connector on MTS-86C to PC 's serial port by using the 25 pin to9 pin
serial cable.
3- Launch the hyper terminal as shown in Fig #1.4.

Fig# 1.4

4- Enter a name, for example MTS-86C, in the Connection Description Window and press OK as shown
in Fig# 1.5

Fig # 1.5

8
5- Select a proper COM port from the connect to Window for example COM2.and press OK as shown
in Fig #1.6

Fig # 1.6

6- In the COM properties Window, select the Baud rate to 19200bits per second, flow control to Xoff /
Xon, and press [OK] as shown in Fig# 1.7

Fig # 1.7

9
7- Press [ RESET] bottom and then press any key among [ A-F] from MTS86 keypad.
The Hyper terminal Window will show the welcome message as shown in Fig#1.8, meaning that the
connection is established between MTS-86C and PC

Fig#1.8

8- To download the machine code to the MTS86C , you need to specify the start address first. We are
going to save the program in (0200:0000) . So input [ L 0200] and press [ ENTER] in command
Prompt, as shown in Fig# 1.9

Fig#1.9

10
9- Now the system is ready to download the program. To download ( the machine code to the MTS-
86C) first select '\" TRANSFER >> SEND FILE" from the menu bar , then browse the Hex file
generated from the assembler [*.HEX] and press [ OPEN] as shown in Fig#1.10

Fig#1.10

10- To execute the program stored in [ 0200:0000] ,you can either use [GO] Command from MTS-86C
Keypad or input [ G=0200:0] the press [ ENTER] in Hyper Terminal Prompt .Press [Y] to confirm
the execution as shown in Fig#1.11

Fig # 1.11

11- You suppose to see 8 LEDs on MTS86C are ON after press [Y].

11
IV- Debugging by Hyper terminal:
In This section, you will use the program that you have downloaded [LED.HEX]. There are many
helpful commands able you to debug your program from Hyper Terminal rather from MTS-86C Keypad.

1- Examine or modify the content of memory E [address]

2- Dump the content of memory to the display D [ start, end]


Input [D 0200:0000] [ ENTER] to examine the data from [0200:0000] to [0200:007F],which are the
machine code we download in previous section

Note: The contents of memory location after [0200:000F] are not considered as part of the download
program[ LED.HEX].

12
3- Examine or modify the content of 8086 register R[Register name]
Input [R][ENTER] to examine the contents of all registers

4- Execution the program [ G]


G[start][break point]: Run the program from start address and terminates at break points
MTS-86C > G=0200:0003, 0009

5- Trace the program [T]


T [ start][count] : Trace the execution of the specified number o instruction. COUNT is
assumed to 1 if omitted.
Input [ T=0200:0000,2]. The program will be executed from 0200:0000 and run 2 instructions at a
time,[MOV SP,4000H] and [ MOV AL,90H] in this example.
MTS-86C > T=0200:0000,2

6-Fill a block in memory with data [F] start ,end, data.


a- Input [ F 0300:0,20,11][ENTER] to fill the data [11] in the memory block [0300:0000] to
[0300:0020].
b- Input [ D 0300:0000][ENTER] to examine the data from [0300:0000] to [0300:0070].

7- Move a block of data from a source location in memory to a destination location. [M


start, end, destination]
a- Input[ M 0200:0000,0020,0300:0000][ENTER]
The data inside [ 0200:0000] ~ [0200:0020] will copied to
[0300:0000] ~[0300 :0020]
b- Input [ D 0200:0000][ENTER] to examine the source data.
13
8- Output data [ O]
O port address, data: Output 8-bit data to port
Input [O3FD2, F0][ENTER]. Since port address 3FD2h is connected to 8255 port B, which is
connected to the LEDs, the 4 bit of LEDs[F0] will ON after command is executed .

MTS-86C > O 3FD2,F0


MTS-86C >-
→ LED display 1111 0000
Table 1.1 I/O Port Address map of MTS86
Port Port Function Device
Address
FFFFH 8255-1 Control Word Register
FFFDH 8255-1 C Port < For Prototyping>
FFFBH 8255-1 B Port Parallel I/O #1 PPI-1
FFF9H 8255-1 A Port
FFFEH 8255-2 Control Word Register
FFFCH 8255-2 C Port < For Prototyping>
FFFAH 8255-2 B Port Parallel I/O #1 PPI-1
FFF8H 8255-2 A Port
FFF2H 8251-1 Command RS232C Port1
FFF0H 8251-1 Data
FFEAH 8279 Status Word Command Keypad Control
FFEBH 8279 Data
FFDEH 8253 Command
FFDCH 8253 Count2 Counter & Timer
FFDAH 8253 Count1
FFD8H 8253 Count 0
FFD2H 8251-2 Command RS232C Port2
FFD0H 8251-2 Data
FFCAH 8259 Command 2 Interrupt Control
FFC8H 8259 Command 1
FFC5H LCD Data Write
FFC3H LCD Instruction (Status) Read LCD
FFC1H LCD Instruction (Command) Write
3FF0H FND 7 Segment Display
3FD6H 8255-3 Control Word Register <For Experiment>
3FD4H 8255-3 C Port Port C to Speaker
3FD2H 8255-3 B Port Port B to LED(8 bit)
3FD0H 8255-3 A Port Port A to Switch

14

You might also like