Expt No: 8086 Programming Date: Addition & Subtraction
Expt No: 8086 Programming Date: Addition & Subtraction
Expt No: 8086 Programming Date: Addition & Subtraction
AIM:
To write an Assembly Language Program (ALP) for performing the
addition and subtraction operation of two byte numbers.
APPARATUS REQUIRED:
PROBLEM STATEMENT:
Write an ALP in 8086 to add and subtract two byte numbers stored in the
memory location 1000H to 1003H and store the result in the memory location
1004H to 1005H.Also provide an instruction in the above program to consider
the carry also and store the carry in the memory location 1006H.
ALGORITHM:
(i) 16-bit addition
h) Initialize the MSBs of sum to 0
i) Get the first number.
j) Add the second number to the first number.
k) If there is any carry, increment MSBs of sum by 1.
l) Store LSBs of sum.
m) Store MSBs of sum.
FLOWCHART
ADDITION SUBTRACTION
START START
YES
A=A+B
IS THERE
ANY CY
YES
NO COUNTER =
IS THERE
ANY COUNTER + 1
CARRY COUNTER =
COUNTER + 1
STORE THE
DIFFERENCE
NO
STOP
2
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
ADDITION
PROGRAM COMMENTS
SUBTRACTION
PROGRAM COMMENTS
3
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:.
ADDITION
MEMORY
DATA
SUBTRACTION
MEMORY
DATA
MANUAL CALCULATION
Thus addition & subtraction of two byte numbers are performed and the result is stored.
4
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To write an Assembly Language Program (ALP) for performing the
multiplication and division operation of 16-bit numbers .
APPARATUS REQUIRED:
PROBLEM STATEMENT:
ALGORITHM:
(i) Multiplication of 16-bit numbers:
a) Get the multiplier.
b) Get the multiplicand
c) Initialize the product to 0.
d) Product = product + multiplicand
e) Decrement the multiplier by 1
f) If multiplicand is not equal to 0,repeat from step (d) otherwise store the
product.
5
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOWCHART
MULTIPLICATION DIVISION
Start
Start
QUOTIENT = 0
REGISTER=00
DIVIDEND =
DIVIDEND-DIVISOR
REGISTER =
REGISTER +
MULTIPLICAND
QUOTIENT = QUOTIENT+1
Multiplier=MU
LTIPLIER 1
IS
NO DIVIDEN
D<
DIVISOR
NO IS
?
MULTIPLIER
=0?
YES
STOP STOP
6
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
MULTIPLICATION
PROGRAM COMMENTS
DIVISION
PROGRAM COMMENTS
7
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:.
MULTIPLICATION
MEMORY
DATA
DIVISON
MEMORY
DATA
MANUAL CALCULATION
Thus multiplication & division of two byte numbers are performed and the result is stored.
8
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To write an Assembly Language Program (ALP) to sort a given array in
ascending and descending order.
APPARATUS REQUIRED:
PROBLEM STATEMENT:
ALGORITHM:
(i) Sorting in ascending order:
a. Load the array count in two registers C1 and C2.
b. Get the first two numbers.
c. Compare the numbers and exchange if necessary so that the two numbers are
in ascending order.
d. Decrement C2.
e. Get the third number from the array and repeat the process until C2 is 0.
f. Decrement C1 and repeat the process until C1 is 0.
(ii)Sorting in descending order:
a. Load the array count in two registers C1 and C2.
b. Get the first two numbers.
c. Compare the numbers and exchange if necessary so that the two numbers are
in descending order.
d. Decrement C2.
e. Get the third number from the array and repeat the process until C2 is 0.
f. Decrement C1 and repeat the process until C1 is 0.
9
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOWCHART
ASCENDING ORDER DESCENDING ORDER
START
START
YES
YES IS
IS
POINTER POINTER
POINTER POINTER NO
+1 NO +1
TEMP = POINTER
TEMP = POINTER POINTER = POINTER + 1
POINTER = POINTER + 1 POINTER + 1 = TEMP
POINTER + 1 = TEMP
POINTER = POINTER +1
POINTER = POINTER +1 COUNT = COUNT + 1
COUNT = COUNT + 1
NO NO
IS
IS
COUNT
COUNT
=0 YES
=0 YES
NO
IS IS
FLAG FLAG
YES
YES = 0
= 0
STOP
STOP
10
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
ASCENDING
PROGRAM COMMENTS
MOV SI,1200H Initialize memory location for array size
MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two datas
JNB L1 If AL < BL go to L1
DEC SI Else, Decrement the memory location
MOV [SI],AL Store the smallest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory location
MOV [SI],BL Store the greatest data in memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not reached zero
HLT Stop
DESCENDING
PROGRAM COMMENTS
MOV SI,1200H Initialize memory location for array size
MOV CL,[SI] Number of comparisons in CL
L4 : MOV SI,1200H Initialize memory location for array size
MOV DL,[SI] Get the count in DL
INC SI Go to next memory location
MOV AL,[SI] Get the first data in AL
L3 : INC SI Go to next memory location
MOV BL,[SI] Get the second data in BL
CMP AL,BL Compare two datas
11
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
JB L1 If AL > BL go to L1
DEC SI Else, Decrement the memory location
MOV [SI],AL Store the largest data
MOV AL,BL Get the next data AL
JMP L2 Jump to L2
L1 : DEC SI Decrement the memory location
MOV [SI],BL Store the smallest data in memory location
L2 : INC SI Go to next memory location
DEC DL Decrement the count
JNZ L3 Jump to L3, if the count is not reached zero
MOV [SI],AL Store data in memory location
DEC CL Decrement the count
JNZ L4 Jump to L4, if the count is not reached zero
HLT Stop
RESULT:.
ASCENDING
MEMORY
DATA
DESCENDING
MEMORY
DATA
Thus given array of numbers are sorted in ascending & descending order.
12
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
LARGEST& SMALLEST
AIM:
To write an Assembly Language Program (ALP) to find the largest and
smallest number in a given array.
APPARATUS REQUIRED:
PROBLEM STATEMENT:
An array of length 10 is given from the location. Find the largest and
smallest number and store the result.
ALGORITHM:
(i) Finding largest number:
a. Load the array count in a register C1.
b. Get the first two numbers.
c. Compare the numbers and exchange if the number is small.
d. Get the third number from the array and repeat the process until C1 is 0.
13
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOWCHART
LARGEST NUMBER IN AN ARRAY SMALLEST NUMBER IN AN ARRAY
START START
INITIALIZE
INITIALIZE
COUNT
COUNT
POINTER MAX =
POINTER MIN = 0
0
PONITER = PONITER =
POINTER + 1 POINTER + 1
YES
IS MAX IS MIN
POINTE
YES POINTE R ?
R ? NO NO
NO NO
IS COUNT = IS COUNT =
0 0
? ?
YES
YES
STORE MAXIMUM STORE MINIIMUM
STOP STOP
14
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
LARGEST
PROGRAM COMMENTS
SMALLEST
PROGRAM COMMENTS
15
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:.
LARGEST
MEMORY
DATA
SMALLEST
MEMORY
DATA
16
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
ALGORITHM:
a. Initialize the data segment .(DS)
b. Initialize the extra data segment .(ES)
c. Initialize the start of string in the DS. (SI)
d. Initialize the start of string in the ES. (DI)
e. Move the length of the string(FF) in CX register.
f. Move the byte from DS TO ES, till CX=0.
START
Initialize DS,ES,SI,DI
`
CX=length of string,
DF=0.
Decrement CX
`
NO Check
for ZF=1
STOP
17
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
COPYING A STRING
PROGRAM COMMENTS
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a string of a particular length is moved from source segment to destination segment.
18
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
SEARCHING A STRING
AIM:
To scan for a given byte in the string and find the relative address of the byte from the
starting location of the string.
ALGORITHM:
a. Initialize the extra segment .(ES)
b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX register.
d. Move the byte to be searched in the AL register.
e. Scan for the byte in ES. If the byte is found ZF=0, move the address pointed by ES:DI
to BX.
START
NO
Check for
ZF=1
Move DI to BX
STOP
19
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
HLT Stop
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY LOCATION
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found .
20
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
ALGORITHM:
a. Initialize the extra segment .(E S)
b. Initialize the start of string in the ES. (DI)
c. Move the number of elements in the string in CX register.
d. Move the byte to be searched in the AL register.
e. Store the ASCII code of the character that has to replace the scanned byte in BL
register.
f. Scan for the byte in ES. If the byte is not found, ZF1 and repeat scanning.
g. If the byte is found, ZF=1.Move the content of BL register to ES:DI.
START
NO
Check for
ZF=1
YES
Move the content of BL
to ES:DI
STOP
21
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
HLT Stop
RESULT:
INPUT
MEMORY
DATA
OUTPUT
MEMORY
DATA
Thus a given byte or word in a string of a particular length in the extra segment(destination)
is found and is replaced with another character.
22
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
NO
IS EOC =
1?
YES
STOP
23
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM TABLE
PROGRAM COMMENTS
Thus the ADC was interfaced with 8086 and the given analog inputs were converted into
its digital equivalent.
EXPT NO: 8086 INTERFACING DATE:
INTERFACING DIGITAL TO ANALOG CONVERTER
AIM :
24
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
25
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
TRANSFER THE
ACCUMULATOR CONTENTS LOAD THE ACC WITH MAX
TO DAC VALUE SEND ACC CONTENT
TO DAC
26
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
27
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:WAVEFORM GENERATION:
Square Waveform
Saw-tooth waveform
Triangular waveform
MODEL GRAPH:
Triangular waveform
Thus the DAC was interfaced with 8085 and different waveforms have been generated.
28
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To write an assembly language program in 8086 to rotate the motor at different speeds.
APPARATUS REQUIRED:
PROBLEM STATEMENT:
Write a code for achieving a specific angle of rotation in a given time and particular
number of rotations in a specific time.
THEORY:
A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a stepwise manner from one
equilibrium position to the next.Two-phase scheme: Any two adjacent stator windings are
energized. There are two magnetic fields active in quadrature and none of the rotor pole faces
can be in direct alignment with the stator poles. A partial but symmetric alignment of the
rotor poles is of course possible.
ALGORITHM:
MEMORY A1 A2 B1 B2 HEX
LOCATION CODE
4500 1 0 0 0 09 H
4501 0 1 0 1 05 H
4502 0 1 1 0 06 H
4503 1 0 1 0 0A H
29
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
FLOWCHART:
START
DELAY
DECREMENT COUNTER
YES
IS B = 0 ?
NO
PROGRAM TABLE
PROGRAM COMMENTS
START : MOV DI, 1200H Initialize memory location to store the array of
number
MOV CX, 0004H Initialize array size
LOOP 1 : MOV AL,[DI] Copy the first data in AL
OUT 0C0,AL Send it through port address
MOV DX, 1010H
L1 : DEC DX Introduce delay
JNZ L1
INC DI Go to next memory location
LOOP LOOP1 Loop until all the datas have been sent
JMP START Go to start location for continuous rotation
1200 : 09,05,06,0A Array of datas
RESULT: Thus the assembly language program for rotating stepper motor in both clockwise
and anticlockwise directions is written and verified.
30
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM :
To display the rolling message HELP US in the display.
APPARATUS REQUIRED:
8086 Microprocessor kit, Power supply, Interfacing board.
ALGORITHM :
Display of rolling message HELP US
1. Initialize the counter
2. Set 8279 for 8 digit character display, right entry
3. Set 8279 for clearing the display
4. Write the command to display
5. Load the character into accumulator and display it
6. Introduce the delay
7. Repeat from step 1.
0 0 0 1 0 0 0 0
0 0 0 D D K K K
DD
00- 8Bit character display left entry
01- 16Bit character display left entry
10- 8Bit character display right entry
11- 16Bit character display right entry
KKK- Key Board Mode
000-2Key lockout.
2.Clear Display: Control word-DC H
1 1 0 1 1 1 0 0
1 1 0 CD CD CD CF CA
31
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
1 0 0 1 0 0 0 0
1 0 0
AI A A A A
Auto increment = 1, the row address selected will be incremented after each of read and
write operation of the display RAM.
FLOWCHART:
SET UP
POINTER
INITIALIZE THE COUNTER
DELAY
32
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM TABLE
PROGRAM COMMENTS
START : MOV SI,1200H Initialize array
MOV CX,000FH Initialize array size
MOV AL,10 Store the control word for display mode
OUT C2,AL Send through output port
MOV AL,CC Store the control word to clear display
OUT C2,AL Send through output port
MOV AL,90 Store the control word to write display
OUT C2,AL Send through output port
L1 : MOV AL,[SI] Get the first data
OUT C0,AL Send through output port
CALL DELAY Give delay
INC SI Go & get next data
LOOP L1 Loop until all the datas have been taken
JMP START Go to starting location
DELAY : MOV DX,0A0FFH Store 16bit count value
LOOP1 : DEC DX Decrement count value
JNZ LOOP1 Loop until count values becomes zero
RET Return to main program
LOOK-UP TABLE:
1200 98 68 7C C8
1204 FF 1C 29 FF
RESULT:
Thus the rolling message HELP US is displayed using 8279 interface kit.
33
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM :
To study different modes of operation of programmable timer 8253
APPARATUS REQUIRED:
THEORY:
ALGORITHM:
Mode 2-
1. Initialize channel 0 in mode 2
2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.
34
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Mode 3-
1. Initialize channel 0 in mode 3
2. Initialize the LSB of the count.
3. Initialize the MSB of the count.
4. Trigger the count
5. Read the corresponding output in CRO.
PORT ADDRESS :
1. CONTROL REGISTER
2. COUNTER OF CHANNEL 0 -
3. COUNTER OF CHANNEL 1 -
4. COUNTER OF CHANNEL 2 -
5. O/P PORT OF CHANNEL 0 -
6. O/P PORT OF CHANNEL 1 -
7. O/P PORT OF CHANNEL 2 -
D7 D6 D5 D4 D3 D2 D1 D0
SC1 SC0 RL1 RL0 M2 M1 M0 BCD
0 0 1 1 0 1 0 0
Mode 2 = 34 H
0 0 1 1 0 1 1 0
Mode 3 = 36 H
0 0 CHANNEL 0 0 0 LATCH
0 1 CHANNEL 1 0 1 LSB
1 0 CHANNEL 2 1 0 MSB
1 1 ----- 1 1 LSB FIRST, MSB NEXT
BCD --0 BINARY COUNTER 1 --BCD COUNTER
M2 M1 M0 MODE
1 CLK 0
0 0 0 MODE 0
0 0 2 CLK
1 1 MODE 1
0 1 0 MODE 2
0 1 3 CLK
1 2 MODE 3
1 0 0 MODE 4
1 0 4 OUT
1 0 MODE 5
PORT PIN ARRANGEMENT DEBOUNCE CIRCUIT
5 OUT 1 CONNECTION
6 OUT 2
* * *
7 GATE 0
8 GATE 1
9 GATE 2 35
10 GND
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM COMMENTS
MOV AL, 34H Store the control word in accumulator
OUT 0BH Send through output port
MOV AL, 0AH Copy lower order count value in accumulator
OUT 08H Send through output port
MOV AL, 00H Copy higher order count value in accumulator
OUT 08H Send through output port
HLT Stop
PROGRAM COMMENTS
MOV AL, 36H Store the control word in accumulator
OUT 0BH Send through output port
MOV AL, 0AH Copy lower order count value in accumulator
OUT 08H Send through output port
MOV AL, 00H Copy higher order count value in accumulator
OUT 08H Send through output port
HLT Stop
36
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
MODEL GRAPH:
FLOW CHART
START
INITIALIZE ACCUMULATOR
WITH MODE SET WORD
STOP
RESULT: Thus an ALP for rate generator and square wave generator are written and
executed.
37
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To study interfacing technique of 8251 (USART) with microprocessor 8086 and
write an 8086 ALP to transmit and receive data between two serial ports with RS232 cable.
APPARATUS REQUIRED:
8086 kit (2 Nos), RS232 cable.
THEORY:
The 8251 is used as a peripheral device for serial communication and is
programmed by the CPU to operate using virtually any serial data transmission technique.
The USART accepts data characters from the CPU in parallel format and then converts them
into a continuous serial data stream for transmission. Simultaneously, it can receive serial
data streams and convert them into parallel data characters for the CPU. The CPU can read
the status of the USART at any time. These include data transmission errors and control
signals. The control signals define the complete functional definition of the 8251. Control
words should be written into the control register of 8251.These control words are split into
two formats: 1) Mode instruction word & 2) Command instruction word. Status word format
is used to examine the error during functional operation.
1...transmit enable
1...data terminal ready
1... receive enable
1... send break character
1.... reset error flags (pe,oe,fe)
1..... request to send (rts)
1...... internal reset
1....... enter hunt mode (enable search for sync characters)
1 ransmitter ready
1. receiver ready
1.. transmitter empty
1... parity error (pe)
1.... overrun error (oe)
1..... framing error (fe), async only
1...... sync detect, sync only
1....... data set ready (dsr)
38
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
ALGORITHM:
1. Initialize 8253 and 8251 to check the transmission and reception of a character
2. Initialize8253 to give an output of 150Khz at channel 0 which will give a 9600 baud rate
of 8251.
3. The command word and mode word is written to the 8251 to set up for subsequent
operations
4. The status word is read from the 8251 on completion of a serial I/O operation, or when
the host CPU is checking the status of the device before starting the next I/O operation
FLOW CHART:
START
No
Is it High
Yes
STOP
39
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RECEIVER END
PROGRAM COMMENTS
MOV AL,36 Initialize 8253 in mode 3 square wave generator
OUT CE,AL Send through port address
MOV AL,10 Initialize AL with lower value of count (clock frequency 150KHz)
OUT C8,AL Send through port address
MOV AL,00 Initialize AL with higher value of count
OUT C8,AL Send through port address
MOV AL,4E Set mode for 8251(8bit data, No parity, baud rate factor 16x & 1 stop bit)
OUT C2,AL Send through port address
MOV AL,37 Set command instruction(enables transmit enable & receive enable bits)
OUT C2,AL Send through port address
L1:IN AL,C2 Read status word
AND AL,02 Check whether receiver ready
JZ L1 If not wait until receiver becomes ready
IN AL,C0 If it is ready, get the data
MOV BX,1500 Initialize BX register with memory location to store the data
MOV [BX],AL Store the data in the memory location
INT 2 Restart the system
RESULT:
Thus ALP for serial data communication using USART 8251 is written and the equivalent
ASCII 41 for character A is been transmitted & received.
40
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To write ALP by interfacing 8255 with 8086 in mode 0, mode 1 and mode 2
APPARATUS REQUIRED:
8086 kit, 8255 interface kit.
ALGORITHM:
Mode 0
1. Initialize accumulator to hold control word
2. store control word in control word register
3. Read data port A.
4. Store data from port A in memory
5. Place contents in port B
Mode 1 & Mode 2
1. Initialize accumulator to hold control word (for port A)
2. Store control word in control word register
3. Initialize accumulator to hold control word (for port B)
4. Place contents in control word register.
5. Disable all maskable interrupts, enable RST 5.5
6. send interrupt mask for RST 6.5 & 7.5
7. Enable interrupt flag
8. Read data from port A, place contents in port B
FLOWCHART
Mode 0 Mode 1 & 2
START
START
Store control word in control register
STOP
STOP
41
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
MODE 0
PROGRAM COMMENTS
MOV AL,90H Set the control word
OUT C6,AL Send it to control port
IN AL,C0 Get the contents of port A in AL
OUT C2,AL Send the contents of port B to port address
HLT Stop
MODE 1
PROGRAM COMMENTS
MOV AL,0B0H Set the control word for mode 1
OUT C6,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT C6,AL Send it to control port
MOV AL,13H Interrupt generation
OUT 30,AL
MOV AL,0AH Through 8259
OUT 32,AL
MOV AL,0FH Using IR2 interrupt(lower order count)
OUT 32,AL
MOV AL,00H Higher order count
OUT 32,AL
STI Set trap flag
HLT Stop
ISR: Subroutine
IN AL,C0 Read from Port A
OUT C2,AL Send it to Port B
HLT Stop
MODE 2
PROGRAM COMMENTS
MOV AL,0C0H Set the control word for mode 2
OUT C6,AL Send it to control port
MOV AL,09H Control for BSR mode
OUT C6,AL Send it to control port
MOV AL,13H Interrupt generation
OUT 30,AL
MOV AL,0AH Through 8259
OUT 32,AL
42
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
I/O mode
D7 D6 D5 D4 D3 D2 D1 D0
1 (1=I/O) GA mode select PA PCU GB mode select PB PCL
D6, D5: GA mode select:
o 00 = mode0
o 01 = mode1
o 1X = mode2
D4(PA), D3(PCU): 1=input 0=output
D2: GB mode select: 0=mode0, 1=mode1
D1(PB), D0(PCL): 1=input 0=output
Result:
Mode 0 Mode 1 Mode 2
Input Output Input Output Input Output
The programs for interfacing 8255 with 8085 are executed & the output is obtained for modes
0,1 & 2
43
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8 BIT ADDITION
AIM:
To write a program to add two 8-bit numbers using 8051 microcontroller.
ALGORITHM:
FLOW CHART:
START
Clear PSW
Select Register
Bank
Load A and R 0
with 8- bit datas
Add A & R 0
STOP
44
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:
OUTPUT
MEMORY LOCATION DATA
4500
Thus the 8051 ALP for addition of two 8 bit numbers is executed.
45
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To perform subtraction of two 8 bit data and store the result in memory.
ALGORITHM:
a. Clear the carry flag.
b. Initialize the register for borrow.
c. Get the first operand into the accumulator.
d. Subtract the second operand from the accumulator.
e. If a borrow results increment the carry register.
f. Store the result in memory.
FLOWCHART:
START
CLEAR CARRY
FLAG
GET IST
OPERAND IN
ACCR
SUBTRACT THE
2ND OPERAND
FROM ACCR
N
IS CF=1
Y
INCREMENT
THE BORROW
REGISTER
STORE
RESULT IN
MEMORY
STOP
46
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:
OUTPUT
MEMORY LOCATION DATA
4500
Thus the 8051 ALP for subtraction of two 8 bit numbers is executed.
47
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8 BIT MULTIPLICATION
AIM:
To perform multiplication of two 8 bit data and store the result in memory.
ALGORITHM:
a. Get the multiplier in the accumulator.
b. Get the multiplicand in the B register.
c. Multiply A with B.
d. Store the product in memory.
FLOWCHART:
START
GET
MULTIPLIER IN
ACCR
GET
MULTIPLICAND
IN B REG
MULTIPLY A
WITH B
STORE
RESULT IN
MEMORY
STOP
48
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8 Bit Multiplication
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A ,#data1 74, data1 Store data1 in
accumulator
4102 MOV B, #data2 75,data2 Store data2 in B reg
RESULT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 4502
4501 4503
Thus the 8051 ALP for multiplication of two 8 bit numbers is executed.
49
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8 BIT DIVISION
AIM:
To perform division of two 8 bit data and store the result in memory.
ALGORITHM:
1. Get the Dividend in the accumulator.
2. Get the Divisor in the B register.
3. Divide A by B.
4. Store the Quotient and Remainder in memory.
FLOWCHART:
START
GET DIVIDEND
IN ACCR
GET DIVISOR IN
B REG
DIVIDE A BY B
STORE
QUOTIENT &
REMAINDER
IN MEMORY
STOP
50
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8 Bit Division
ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 MOV A, # data1 74,data1 Store data1 in
accumulator
4102 MOV B, # data2 75,data2 Store data2 in B reg
RESULT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 (dividend) 4502 (remainder)
Thus the 8051 ALP for division of two 8 bit numbers is executed.
51
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
AIM:
To write an ALP to perform logical and bit manipulation operations using 8051
microcontroller.
APPARATUS REQUIRED:
8051 microcontroller kit
ALGORITHM:
FLOWCHART:
START
STOP
52
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
PROGRAM TABLE
53
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
RESULT:
4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H
54
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
55
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
Receiver:
MOV TMOD,#20H
MOV TL1,#FDH
MOV TH1,#FFH
MOV SCON,#50H
SETB TR1
LOOP: JNB RI,LOOP
MOV A,SBUF
MOV DPTR,#4500H
MOVX @DPTR,A
CLR RI
HERE: SJMP HERE
56
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
SERIAL COMMUNICATION
8051>H
HELP MENU
For SDA SI-MEL kit, following menu is displayed on pressing the option "T"
8051>T
ALS-SDA SI-MEL Kit Test monitor
57
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
6. Exit
Select (1-6):
Suppose the user presses the key '1', following message is displayed if the internal data RAM
is OK.
After displaying the message, the menu is displayed once again waits for user to enter a key
8051>E
EDIT (R,B,M,P,D)D - EXTERNAL DATA RAM
Enter STA address = 0400
0400 = 7F:55 Press 'N' key to go to the next address
0401 = D5:66
0402 = D3:77
0403 = 73:88
0404 = 6F:12
0405 = CB:01
0406 = A7:02 Press 'P' key to go to the previous address
0407 = 6F:03
0408 = 7B:04
0409 = 29:05
040A = 6F:06
040B = 73:07
040C = FF:08
040D = 7D:09 Press 'CR' key to have the same address
040E = 09:90 Press 'ESC' Key to abort the command
8051>E
EDIT (R,B,M,P,D)B - BITS
58
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8051>E
EDIT (R,B,M,P,D)R- REGISTERS
ACC = 00:33
PSW = 00:44
DPH = 00:55
DPL = 00:00
DPL = 00:00
8051>E
EDIT (R,B,M,P,D)-P = PROGRAM CODE
8000 = FF:78
8001 = FF:10
8002 = FF:79
8003 = FF:20
8004 = FF:7A
8005 = FF: 12
8007 = FF : 00
8008 = FF : 03
8009 = FF : 0F
8051>E
EDIT (R,B,M,P,D)-M - INTERNAL RAM
0000 = 00 : 12
0001 = 00 : 34
59
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
0002 = 00 : 00
DISPLAY COMMAND
8051>D
EDIT (R,B,M,P,D)-EXTERNAL DATA RAM
0500 55 66 77 88 12 01 02 03 04 05 06 07 08 09 04 D7
8051>B
BR _ NO: R
BR_ADD 0000
ERROR! ONLY A BREAKS ALLOWED
8051>B
BR _ NO: 0
ERROR! BREAK NUMBERS MUST BE BETWEEN 1 & 8
8051>C
BR_N0:A Clears all the break point set by the user
8051>C
BR_N0:1 Clears the break point number 1
60
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
8051>A
ENTER START ADDRESS = 8000
61
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
EX. NO. PROGRAMS FOR DIGITAL CLOCK AND STOP WATCH (USING
8086)
DATE:
Program that places a message on the screen every 10 seconds, using int 1ah;
CODE SEGMENT
TIMEDELAY:
MOV SP,1000H
MOV DI,10XD
TIME OUT:
MOV AH,00H
INT 1AH
MOV BX,DX
TIMER:
MOV AH, 00H
INT 1AH
SUB DX, BX
CMP DX, 182XD
JC TIMER
MOV AH, 09H
CS MOV DX,MSG
INT 21H
DEC DI
JNZ TIMEOUT
MOV AX,4C00H
INT 21H
MSG:
DB 'TEN MORE SECONDS HAVE PASSED $'
CODE ENDS
62
EC 2308 MICROPROCESSOR AND MICROCONTROLLER LAB DEPT OF ECE
A0 Address with A0 = 0
A1 Address with A0 = 1
Using 8086:
MOV AL,ICW1
OUT A0,AL
MOV AL,ICW2
OUT A1,AL
MOV AL,ICW4
OUT A1,AL
MOV AL,OCW1
OUT A1,AL
STI
HLT
63