Professional Documents
Culture Documents
and
Microcontrollers
MPECC08
Practical File
Rohan Deswal
2020UMP1071
Contents
1. Write a program to add and subtract a 16-bit number in 8086 with and without carry.
2. Write a program to multiply two 8-bit numbers by repetitive addition method using 8085
3. Write a program to generate Fibonacci series 8085 program to generate Fibonacci series.
4. Write a program to generate a factorial of number.
5. Write a program to read 16-bit data from a port and display the same in another port
6. Write an assembly language program in 8085 microprocessor which generates 1 KHz square
waveform by using counter 1 as a binary counter if clock frequency of 8254 is 2 MHz
7. Write a program to generate a square wave of 10 KHz using Timer 1 in mode 1.
8. Write program to transfer data from external ROM to internal(using8051)
Experiment 1
Write a program to add and subtract a 16-bit number in 8086 with and without carry.
Problem
Write a program to add two 16-bit numbers where starting address is 2000 and the
numbers are at 3000 and 3002 memory address and store result
into 3004 and 3006 memory address.
Algorithm
1. Load 0000H into CX register (for carry)
2. Load the data into AX (accumulator) from memory 3000
3. Load the data into BX register from memory 3002
4. Add BX with Accumulator AX
5. Jump if no carry
6. Increment CX by 1
7. Move data from AX (accumulator) to memory 3004
8. Move data from CX register to memory 3006
9. Stop
Problem
Write a program to subtract two 16-bit numbers where starting address is 2000 and the
numbers are at 3000 and 3002 memory address and store result
into 3004 and 3006 memory address.
Algorithm
1. Load 0000H into CX register (for borrow)
2. Load the data into AX (accumulator) from memory 3000
3. Load the data into BX register from memory 3002
4. Subtract BX with Accumulator AX
5. Jump if no borrow and Increment CX by 1
6. Move data from AX (accumulator) to memory 3004
7. Move data from CX register to memory 3006
8. Stop
Memory Instructions Comment
2000 MOV CX, 0000 [CX] <- 0000
2003 MOV AX, [3000] [AX] <- [3000]
2007 MOV BX, [3002] [BX] <- [3002]
200B SUB AX, BX [AX] <- [AX] – [BX]
200D JNC 2010 Jump if no borrow
200F INC CX [CX] <- [CX] + 1
2010 MOV [3004], AX [3004] <- [AX]
2014 MOV [3006], CX [3006] <- [CX]
2018 HLT Stop
Experiment 2
Write a program to multiply two 8-bit numbers by repetitive addition method using 8085
Procedure
The 8085 has no multiplication operation. To get the result of multiplication, we should use
the repetitive addition method.
After multiplying two 8-bit numbers it may generate 1-byte or 2-byte numbers, so we are
using two registers to hold the result.
We are saving the data at location 8000H and 8001H. The result is storing at location 8050H
and 8051H.
Program
Address Instructions Comments
F000 LXI H,8000H Load first operand address
Output
Address Data
8050 93
8051 D0
Experiment 3
Write a program to generate Fibonacci series 8085 program to generate Fibonacci series.
Problem
Write an assembly language program in 8085 microprocessors to generate Fibonacci series.
Example
Assume Fibonacci series is stored at starting memory location 3050.
Algorithm
1. Initialize register H with 30 and register L with 50, so that indirect memory M
points to memory location 3050.
2. Initialize register B with 00, register C with 08 and register D with 01.
3. Move the content of B in M.
4. Increment M by 1 so that M points to next memory location.
5. Move the content of D in M.
6. Move the content of B in accumulator A.
7. Add the contents of D in A.
8. Move the content of D in B.
9. Move the content of A in D.
10. Increment M by 1 so that M points to next memory location.
11. Move the content of A in M.
12. Decrements C by 1.
13. Jump to memory location 200C if ZF = 0 otherwise Halt the program
Program
Address Instructions Comment
2000 LXI H, 3050 H <- 30, L <- 50
2003 MVI C, 08 C <- 08
2005 MVI B, 00 B <- 00
2007 MVI D, 01 D <- 01
2009 MOV M, B M <- B
200A INX H M <- M + 01
200B MOV M, D M <- D
200C MOV A, B A <- B
200D ADD D A <- A + D
200E MOV B, D B <- D
200F MOV D, A D <- A
2010 INX H M <- M + 01
2011 MOV M, A M <- A
2012 DCR C C <- C – 01
2013 JNZ 200C Jump if ZF = 0
2016 HLT END
Experiment 4
Write a program to generate a factorial of number.
Problem
Write an assembly language program for calculating the factorial of a number using the
8085 microprocessors.
In 8085 microprocessors, no direct instruction exists to multiply two numbers, so
multiplication is done by repeated addition as 4×3 is equivalent to 4+4+4 (i.e., 3 times).
Load 04H in D register -> Add 04H 3 times -> D register now contains 0CH -> Add 0CH 2
times -> D register now contains 18H -> Add 18H 1 time -> D register now contains 18H ->
Output is 18H
Algorithm
1. Load the data into register B
2. To start multiplication set D to 01H
3. Jump to step 7
4. Decrements B to multiply previous number
5. Jump to step 3 till value of B>0
6. Take memory pointer to next location and store result
7. Load E with contents of B and clear accumulator
8. Repeatedly add contents of D to accumulator E times
9. Store accumulator content to D
10. Go to step 4
Problem
Write an 8086 program to Print a 16-bit Decimal number.
Examples
Input: d1 = 655
Output: 655
Input: d1 = 234
Output:234
Explanation
1. Load the value stored into register
2. Divide the value by 10
3. Push the remainder into the stack
4. Increase the count
5. Repeat the steps until the value of the register is greater than 0
6. Until the count is greater than zero
7. Pop the stack
8. Add 48 to the top element to convert it into ascii
9. Print the character using interrupt
10. Decrements the count
Program
;8086 program to print a 16-bit decimal number
. MODEL SMALL
. STACK 100H
.DATA
d1 dw 655
. CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
; interrupt to exit
MOV AH,4CH
INT 21H
MAIN ENDP
PRINT PROC
; initialize count
Experiment 6
Problem
Write an assembly language program in 8085 microprocessor which generates 1 KHz
square waveform by using counter 1 as a binary counter if clock frequency of 8254 is 2
MHz
Assumption
Assume the port addresses are 80 H, 81 H, 82 H, 83 H for C0(Counter 0), C1(Counter 1),
C2(Counter 2), CR (Control Register).
For the above problem, 8254 must work in Mode 3 which is the square wave generator.
Count for register is given as clock frequency / square wave frequency
count = 2 MHz / 1 KHz = 2000 = (07D0) H
Now the data is 16 bit so value of RW1 = 1 and RW0 = 1 in Control Register. As we want to
select C1 (Counter 1) the value of SC1 = 0 and SC0 = 1 in Control Register. Value of M2 = 0,
M1 = 1 and M2 = 1 for Mode 3 in Control Register. For binary counter value of LSB in CR is
0.
Algorithm
1. Move the data 76 in A
2. Display the contents of A to port 83
3. Move the data D0 in A
4. Display the contents of A to port 81
5. Move the data 07 in A
6. Display the contents of A to port 81
7. Stop
Program
Memory address Instructions Comment
2000 MVI A 76 A <- 76
2002 OUT 83 CR <- A
2004 MVI A D0 A <- D0
2006 OUT 81 C1 <- A
2008 MVI A 07 A <- 07
200A OUT 81 C1 <- A
200C HLT Stop
Explanation
1. MVI A 76 is used to move the content of CR (Control Register) to register A.
2. OUT 83 is used to assign the value of A to port 83 which is Control Register
3. MVI A D0 is used to move the move the lower byte of data of Counter 1 to register A.
4. OUT 81 is used to assign the value of A to port 81 which is Counter 1.
5. MVI A 07 is used to move the move the higher byte of data of Counter 1 to register A.
6. OUT 81 is used to assign the value of A to port 81 which is Counter 1.
7. HLT is used end the program.
Experiment 7
Write a program to generate a square wave of 10 KHz using Timer 1 in mode 1.
Square wave generation using 8051 timers.
Square waves of any frequency (limited by the controller specifications) can be generated
using the 8051 timers. The technique is very simple. Write up a delay subroutine with delay
equal to half the time period of the square wave. Make any port pin high and call the delay
subroutine. After the delay subroutine is finished, make the corresponding port pin low and
call the delay subroutine gain. After the subroutine is finished, repeat the cycle again. The
result will be a square wave of the desired frequency at the selected port pin. The circuit
diagram is shown below and it can be used for any square wave, but the program has to be
accordingly. Programs for different square waves are shown below the circuit diagram.
In 8051, the oscillator output is divided by 12 using a divide by 12 network and then fed to
the Timer as the clock signal. That means for an 8051 running at 12MHz, the timer clock input
will be 1MHz. That means the timer advances once in every 1uS and the maximum time delay
possible using a single 8051 timer is (2^16) x (1µS) = 65536µS. Delays longer than this can be
implemented by writing up a basic delay program using timer and then looping it for a
required number of times. We will see all these in detail in next sections of this article.
Program
ACALL DELAY
CLR P1.0
ACALL DELAY
SJMP MAIN
CLR TR0
CLR TF0
SETB P1.0
RET
END
Experiment 8
Write program to transfer data from external ROM to internal(using8051)
Overview
For minimal memory applications, the 8051 has internal data and code memory. In such a
position. For certain applications, this memory capacity will not be adequate. To expand the
memory space of the 8051 micro-controllers, we must bind external ROM/EPROM and
RAM. We also understand that ROM serves as program memory and RAM serves as data
memory. Let’s take a look at how the 8051 accesses these memories.