Professional Documents
Culture Documents
MPC 8086 Lab Manual
MPC 8086 Lab Manual
and
Microcontrollers
Laboratory
Manual
DK Raheja
Contents
1(a). Write a program to add two 16-bit numbers with/without carry using 8086 microprocessor. .... 1
1(b). Write a program to subtract two 16-bit numbers with/without borrow using 8086
microprocessor. ...................................................................................................................................... 5
2. Write a program to multiply two 8-bit numbers by repetitive addition using 8086. ......................... 9
3. Write a program to generate Fibonacci series up to 16 terms. ........................................................ 13
4. Write a program to generate factorial of a number from 0 to 9. ..................................................... 17
5 .Write a program to read 16 bit data from a port and display the same in another port. ................ 23
7 .Write a program to generate square wave of 10 KHz using timer 1 in mode 1(using 8051
microcontroller). ................................................................................................................................... 27
9. Write a program to transfer data from ROM memory to RAM memory. .................................... 31
10. Write a program for the traffic light controller using 8086 microprocessor. ................................. 35
1(a). Write a program to add two 16-bit numbers with/without
carry using 8086 microprocessor.
Start
Yes
Is carry
Increment
generated
the CX
?
register
No
Stop
1
2003 MOV AX,92F0 Move data 92F0H to AX
register
2006 MOV BX,92F0 Move data 92F0H to BX
register
2009 ADD AX, BX Add the content of AX and
BX registers
200B JNC 200E Jump to the address 200EH if
no carry is generated from
the AX register
200D INC CX Increment the content of CX
register
200E MOV [3004], AX Move the content to AX
register to the address 3004H
2012 MOV [3006], CX Move the content to CX
register to the address 3004H
2016 INT 3 Call the interrupt type 3 to
insert breakpoint
2
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.
Figure 1.16 bit Addition using Assembler Directives in the 8086 emulator.
3
Result on 8086 emulator
The two same 16 -bit numbers are added, which are stored at the memory address labelled as
NUM1 and NUM2. The sum of the two numbers are stored at the memory address labelled as
SUM and the carry is stored at the memory address labelled as CARRY as shown in the Figure
2(. i.e., 92F0 H+92F0 H=125E0 H).
Figure 2. Output of the addition of two 16-bit numbers using 8086 emulator
4
1(b). Write a program to subtract two 16-bit numbers with/without
borrow using 8086 microprocessor.
Start
Yes
Is borrow
Increment
generated
the CX
register
No
Stop
5
2003 MOV AX,92F0 Move data 92F0 H to AX
register
2006 MOV BX,60AE Move data 60AE H to BX
register
2009 SUB AX, BX Subtract the content of BX
register from AX register
200B JNC 200E Jump to the address 200EH if
no borrow from the AX
register
200D INC CX Increment the content of CX
register
200E MOV [3004], AX Move the content to AX
register to the address 3004H
2012 MOV [3006], CX Move the content to CX
register to the address 3004H
2016 INT 3 Call the interrupt type 3 to
insert breakpoint
6
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.
7
Figure 4 Output of the subtraction of two 16-bit numbers using 8086 emulator
8
2. Write a program to multiply two 8-bit numbers by repetitive
addition using 8086.
Start
Initialize AL register
with 00H
Initialize CL register
with 00H
Add content of AL
and BL registers
No
Is carry
generate
d?
Yes
Stop
Increment the CL
register by one
Move the result from
the AX register to
Decrement the DL memory address
register by one 3004H
10
Result on 8086 trainer kit
The two same 8 bit numbers are multiplied, which is FF H. Output shown in the 8086 Trainer
Kit is 0000:3004 01 FE 09 00.Where 01H is the lower byte at address 3004H,FEH is the upper
byte at address 3005H.Therefore, the multiplication of the two numbers=FE01 H.
11
Result on 8086 emulator
The two same 8 -bit numbers are multiplied, which are stored at the memory address labelled
as NUM1 and NUM2. The multiplication of the two numbers are stored at the memory address
labelled as ANS as shown in the Figure 6(. i.e., FF H×FF H=FE01 H).
12
3. Write a program to generate Fibonacci series up to 16 terms.
Start
Yes
Is data in No
CL register Stop
not zero?
13
Program written on 8086 emulator
Memory Address Instruction Comment
1100 MOV CL,10 Move the number of terms (.i.e.,10H) in the CL
register
1102 MOV BL,00 Initialize BL register with 0H
1104 MOV DL,01 Initialize DL register with 01H
1106 MOV DI,2000 Move the starting location of the result in the DI
register
1109 MOV AL,DL Move data from DL register to AL register
110B ADD AL,BL Add data in AL and BL registers
110D MOV [DI],AL Move the data from AL register to the address
stored in DI register
110F INC DI Increment the DI register to go to the next memory
location
1110 MOV BL,DL Move data from DL to the BL register
1112 MOV DL,AL Move data from AL to DL register
1114 DEC CL Decrement the CL register by one
1116 JNZ 110B Jump to the 110B address if data in CL register is
not zero
1118 INT 3 Call the interrupt type 3 to insert breakpoint
14
The first terms .i.e., 01H is at the 2000H address, second term .i.e., 02H is at 2001H address,
third term .i.e., 03H is at 2002 H address and so on. Therefore the generated Fibonacci series
is 01H,02H,03H,05H,08H,0DH,15H,22H,37H,59H,90H,E9H,79H,62H,DBH and 3DH.
15
Result on 8086 emulator
The number of terms of the Fibonacci series is 16. The output of the generated Fibonacci series
is shown in the Figure 8.The generated Fibonacci series is
01H,02H,03H,05H,08H,0DH,15H,22H,37H,59H,90H,E9H,79H,62H,DBH and 3DH.
16
4. Write a program to generate factorial of a number from 0 to 9.
Yes
Is data
= 00h
No
Yes Is data in BX
register not
equal to zero?
No
Stop
17
Program written on trainer kit:
Memory Address Instruction Comment
2000 MOV BX, [0500] Move data from memory address
0500 to BX register
2004 MOV AX,01 Move data 01H in AX register
2007 MOV CX,01 Move data 01H in CX register
200A MOV DX,00 Move data 00H in DX register
200D CMP BX,00 Compare data in BX register
with 00H
2011 JZ 2019 Jump if data in BX register is
zero to memory address 2019H
2013 MUL CX Multiple data in CX register with
data in AX register
2015 INC CX Increment data in CX register
2016 DEC BX Decrement data in BX register
2017 JNZ 2013 Jump if data in BX register is not
zero to memory address 2013H
2019 MOV [3004], AX Move the data in AX register to
the memory address 3004H
201D MOV [3006], DX Move the data in DX register to
the memory address 3006H
2021 INT 3 Call the interrupt type 3 to insert
breakpoint
18
Result on 8086 trainer kit:
Factorial of nine
0000:3004 80 89 05 00
According to the above result, the factorial of 9 is 0058980H.
Factorial of zero
0000:3004 01 00 00 00
According to the above result, the factorial of 0 is 00000001H
Figure 9. Message.
19
Program on 8086 emulator
20
AX and upper word of the result is moved to the memory address labelled as FACTDX.As
shown in the Figure 12, factorial of 9 is 00058980H.
Factorial of zero
For finding the factorial of the nine, number 0 is entered on the emulator screen. After executing
the program, the lower word of the result is moved to the memory address labelled as FACT
AX and upper word of the result is moved to the memory address labelled as FACTDX.As
shown in the Figure 14, factorial of 9 is 0000 0001H.
21
Figure 13.Assembler takes 0 as user input.
22
5 .Write a program to read 16 bit data from a port and display
the same in another port.
Stop
23
Program
Assembler Directives Instruction Comment
. MODEL SMALL Select the small model
.DATA Start Data segment
READ_P1 DW? 16 bit space is allocated
starting at memory location
READ_P1
WRITE_P2 DW? 16 bit space is allocated
starting at memory location
WRITE_P2
.CODE Start Code segment
.STARTUP Start program
DATA1 EQU 1234H Data 1234H is replaced by
the name DATA1
PORT1 EQU 112 Port address 112 is replaced
by name PORT1
PORT2 EQU 110 Port address 110 is replaced
by name PORT2
MOV AX, DATA1 Move 16 bit data in AX
register
OUT PORT1,AX Write the data into PORT1
from AX register
MOV AX,0 Reset the AX register
IN AX,PORT1 Read the data in AX register
from PORT1
MOV [READ_P1],AX Move the data to memory
location READ_P1 from the
AX register
OUT PORT2,AX Write the data into PORT2
from AX register
IN AX,PORT2 Read the data in AX register
from PORT2
MOV [READ_P2],AX Move the data to memory
location READ_P2 from the
AX register
.EXIT Terminate the execution
END End of program
Procedure
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 15.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the Run Tab to execute
the program.
4. To check the result, click on the Vars Tab which is at the bottom of the dialog box.
5. The output can be seen by clicking the virtual devices tab as shown in the Figure 16.
24
Figure 15. Program to read16 bit data from port1 and display the same on Port2
25
Result
As shown in the Figure 17, 1234H is read from the port 1 and moved the memory address
labelled as READ_P1.The same data is written on the port 2 and moved to the memory address
labelled as READ_P2.
The same data is shown at both ports with port addresses 110 and 112 as shown in the Figure
18.The data read on the port 112 is 1234H and on port 110 is 34H. The data shown in the port
110 is lower byte of the 16 bit data because port 110 is inbuilt programmed to show only lower
8 bit of data.
26
7 .Write a program to generate square wave of 10 KHz using
timer 1 in mode 1(using 8051 microcontroller).
27
Flow Chart
Start
DELAY (Subroutine)
Move 10 H in the
Move FFH to higher
TMOD register
nibble of Timer 1
Main
Program Move 00H to the port1
Move CD H to lower
nibble of Timer 1
Move FFH to the port1
Set the Timer 1
Short Jump
Check the overflow
condition of Timer 1
Stop
Program
Assembler Directive Instruction Comment
ORG 0000H Starting address of the
program is 0000H
TMOD_REG EQU 10H 10 H is replaced by
TMOD_REG
COUNT_H EQU 0FFH 0FFH is replaced by
COUNT_H
COUNT_L EQU 0CDH 0CD H is replaced by
COUNT_L
P1_H EQU 0FFH 0FFH is replaced by P1_H
P1_L EQU 00H 00H is replaced by P1_L
MOV TMOD Move 10H in TMOD register
,#TMOD_REG
BACK MOV P1,#P1_L Move 00H to the port1
ACALL DELAY Call the DELAY subroutine
MOV P1,#P1_H Move FF H to the port1
ACALL DELAY Call the DELAY subroutine
SJMP BACK Short jump to the BACK
28
DELAY MOV TH1,#COUNT_H Move FFH to the lower byte
of Timer1
MOV TL1,#COUNT_L Move CDH to the higher
byte of Timer1
SETB TR1 Start the Timer 1
LOOP JNB TF1,LOOP Monitor the Timer 1 flag
CLR TR1 Stop the Timer 1
CLR TF1 Clear the Timer 1 flag
RET Return to the main program
END End of program
Procedure
1. Go to the Tab ‘Project’ and select ‘New µvision Project’. After that give the project name
and save it.
2. Then a dialog box appers automatically for selecting the reqiured 8051 chip. Select
Microchip and then select AT 89C51 microcontroller chip.
3. Go to the File Tab.Click on ‘New’ tab . Then a new page named’Text1’ appears, in which
we write the program as shown in the Figure 21.
4. After writing the program, Save it with name same as before with the extension of .asm
(for assembly language program). After saving , all the keywords are highlighted.
5. Right click on Target1 (on the project Window) ,a dialog box appears. Now go to ‘Options
for Target ‘Target’ Tab and then, change the crystal frequency of the microcontroller (for
AT89C51) to 11.0592 GHz.
6. Now, click on icon to translate for running the first time .This will give errors and
29
Figure 19. Program to generate square wave in Keil software.
Result
The generated square wave of 10 KHz on Port 1 is shown in the Figure 20.
30
9. Write a program to transfer data from ROM memory to RAM
memory.
Apparatus: Keil µVision5 Software
Flow Chart
Start
No
Is counter
zero?
Stop
31
Program
Assembler Directive Instruction Comment
ORG 0000H Starting address of the
program is 0000H
ROM_POINTER EQU Replace 600H with
600H ROM_POINTER
RAM_POINTER EQU 60H Replace 60H with
RAM_POINTER
COUNTER EQU 06H Replace 06H with
COUNTER
MOV DPTR, Load the ROM pointer in
#ROM_POINTER DPTR register
MOV R0,#RAM_POINTER Load the RAM pointer in R0
register
MOV R7,#COUNTER Load the counter in R7
register
BACK MOVC A,@ A+DPTR Move the data from ROM
code space to Accumulator
MOV @R0,A Save it in the RAM
INC DPTR Increment the ROM pointer
INC R0 Increment the RAM pointer
CLR A Clear the Accumulator
DJNZ R7,BACK Decrement R7 and jump if R7
is not zero to BACK
ORG 600H Go to the ROM address 600H
DB Save the six 8-bit numbers
23H,45H,55H,67H,88H,97H
END End of program
Procedure
1. Go to the Tab ‘Project’ and select ‘New µvision Project’. After that give the project name
and save it.
2. Then a dialog box appers automatically for selecting the reqiured 8051 chip. Select
Microchip and then select AT 89C51 microcontroller chip.
3. Go to the File Tab.Click on ‘New’ tab . Then a new page named’Text1’ appears, in which
we write the program as shown in the Figure 21.
4. After writing the program, Save it with name same as before with the extension of .asm
(for assembly language program). After saving , all the keywords are highlighted.
5. Right click on Target1 (on the project Window) ,a dialog box appears. Now go to ‘Options
for Target ‘Target’ Tab and then, change the crystal frequency of the microcontroller (for
AT89C51) to 11.0592 GHz.
6. Now, click on icon to translate for running the first time .This will give errors and
32
8. To see ROM memory, write C:600H in the memory window (Select from View Tab) and
to see RAM memory, write D:60H in the same the memory window.
9. To run the program ,click on the icon .
Figure 21. Program to transfer data from ROM memory to RAM memory.
Result
ROM memory is shown in the Figure 22, containing the saved six 8-bit numbers and RAM
memory is shown in the Figure 23, containing the same six 8-bit numbers (after the execution
of program).
33
Figure 23. RAM Memory
34
10. Write a program for the traffic light controller using 8086
microprocessor.
Yes Is Situation
below from
SIT_END?
No
Move the offset of memory
address ’SITUATION’ in the SI
register
Stop
35
Program
Assembler Directives Instructions Comment
.MODEL SMALL Select the small model
.DATA Start data segment
SITUATION DW Allocate space starting
030CH,069AH,0861H,0861H,04D3H at the memory address
‘SITUATION’ for five
16 bit number.
.CODE Start code segment
.STARTUP Start the program
SIT_END EQU $ Replace $ with name
‘SIT_END’
ALL_RED EQU 0249H Replace number 0249H
with name ‘ALL_RED’
MOV AX,ALL_RED Move all_red data in
AX register
OUT 04H,AX Write the data on port
address 04H
MOV SI,OFFSET Move the offset of
SITUATION memory address
‘SITUATION’ in the SI
register
NEXT MOV AX,[SI] Move the data from
memory address
pointed by the register
SI in AX register
OUT 04H,AX Write that data on port
address 04H
MOV CX,4CH Move the higher order
word of count for delay
in register CX
MOV DX,4B40H Move the lower order
word of count for delay
in register DX
MOV AH,86H Interrupt of wait/delay
INT 15 H
ADD SI,2 Go to the next word
CMP SI,SIT_END Compare data in SI
register with SIT_END
JB NEXT Jump if below to NEXT
MOV SI,OFFSET Again, Move the offset
SITUATION of memory address
’SITUATION’ in the SI
register
JMP NEXT
.EXIT Terminate the program
execution
36
END Stop reading the
program
Procedure
1. Press New Tab, select COM template and press OK.
2. Delete the previously written instructions and type the program as shown in the Figure 24.
3. Click on the Emulate Tab and a dialog box appears. Then, click on the virtual devices tab
and then select traffic light option.
4. To execute the program click on Run Tab to the output.
37
ALL_RED is used to turn ON all the red lights to stop the traffic.
SITUATION (030CH) is used to move traffic in north and south direction.
SITUATION (069AH) is used to make the traffic wait.
SITUATION (0861H) is used to move traffic in east and west direction.
SITUATION (04D3H) is used to make the traffic wait.
38