Microprocessor Assignment
Microprocessor Assignment
SECTION: G3(UG3)
LDA: - Load accumulator. (this instruction copies the data from a given 16-bit
address to the accumulator)
Algorithm:
• Reset
• Assign Memory value
• Assign Load Accumulator Hex Code to the destined memory.
• Halt the program
• Execute the program.
Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Halt the program
• Execute the program.
Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Copy the value of 8-bit data in Accumulator to B register using MOV.
• Halt the program.
• Execute the program.
STA: - the content of accumulator are copied into the memory location.
Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Use STA to store the content of the accumulator in some memory location.
• Halt the program
• Execute the program.
Algorithm:
• Reset
• Assign memory Value
• Assign two values at memory location 8500H and 8501H respectively
• Reset
• Assign some other memory value.
• Load accumulator with the first location of the stored data above.
• Copy accumulator data to register B
• Load accumulator with the next stored data.
• Store the value of the accumulator at the first location.
• Copy the value of Register B into the accumulator.
• Store the value of accumulator into the other location.
• Halt the program.
• Execute.
Algorithm:
• Reset
• Assign Memory
• Initialize the carry as 0
• Load the first 8-bit data into the accumulator
• Copy the contents of accumulator into the register B
• Load the second 8-bit data into the accumulator
• Add the 2 - 8-bit data and check for carry
• Jump on if no carry
• Increment carry if there is
• Store the added request in accumulator
• Move the carry value to accumulator
• Store the carry value in accumulator
• Halt
• Execute
Case 1: Case 2:
8000 78 8000 23
8001 5D 8001 CF
Output
Case 1: Case 2:
8050 1B 8050 54
8051 00 8051 01
Explanation –
1. LHLD 2050 loads the value at 2050 in L register and that in 2051 in H register
(first number)
2. XCHG copies the content of H to D register and L to S register
3. LHLD 2052 loads the value at 2052 in L register and that in 2053 in H register
(second number)
4. DAD D adds the value of H with D and L with E and stores the result in H and L
5. SHLD 3050 stores the result at memory location 3050
6. HLT stops execution
Program –
MEMORY
LHLD
LHLD
7. Write 8085 Assembly language program to find the largest and smallest number in
the given array: 02H, 01H, FFH, 04H, 40H, 20H, 50H.
2050 02
2051 01
2052 FF
2053 04
2054 40
2055 20
2056 50
In CMP instruction:
If Accumulator > Register then carry and zero flags are reset
If Accumulator = Register then zero flag is set
If Accumulator < Register then carry flag is set
Algorithm –
1. Maximum number is stored in B register and minimum in C register
2. Load counter in D register
3. Load starting element in Accumulator, B and C register
4. Compare Accumulator and B register
5. If carry flag is not set then transfer contents of Accumulator to B. Else, compare
Accumulator with C register, if carry flag is set transfer contents of Accumulator
to C
6. Decrement D register
7. If D>0 take next element in Accumulator and go to point 4
8. If D=0, store B and C register in memory
9. End of program
Program-
ADDRESS LABEL INSTRUCTION COMMENT
LXI H,
LXI H,
Explanation –
1. One by one all elements are compared with B and C register.
2. Element is compared with maximum, if it greater than maximum then it is stored
in B register. Else, it is compared with minimum and if it is less than minimum
then it stored in C register.
3. Loop executes 10 number of times.
4. At the end of 10 iterations, maximum and minimum are stored at 2060H and
2061H respectively.
-- Program
21
8000 Setup HL pair as a pointer for source
50 START: LXI H, 8050H
memory.
80
11
70 Set up DE pair as a pointer for destination
8003 LXI D, 8070H
memory
80
C2
08 If counter is not 0, go back to transfer next
800D JNZ LOOP
byte.
80
-- Program
21
80
21
80
Algorithm –
1. We are taking adding the number 43 seven(7) times in this example.
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so
we need register pair to store the result.
Program –
MEMORY ADDRESS MNEMONICS COMMENT
2012 HLT
Assumption – Size of list is stored at 2040H and list of numbers from 2041H
onwards.
Algorithm –
1. Load size of list in C register and set D register to be 0
2. Decrement C as for n elements n-1 comparisons occur
3. Load the starting element of the list in Accumulator
4. Compare Accumulator and next element
5. If accumulator is less than next element jump to step 8
6. Swap the two elements
7. Set D register to 1
8. Decrement C
9. If C>0 take next element in Accumulator and go to point 4
10. If D=0, this means in the iteration, no exchange takes place consequently we
know that it won’t take place in further iterations so the loop in exited and
program is stopped
11. Jump to step 1 for further iterations
Program –
ADDRESS LABEL INSTRUCTION COMMENT
200FH MOV M, A
2010H DCX H
2011H MOV M, B
2012H INX H
ADDRESS LABEL INSTRUCTION COMMENT
Transfer contents of D to
Program
Address Hexcodes Labels Mnemonics Comments
800B D2, 14, 80 JNC NEXTBYT If (A) >= second byte, do not exchange
Assignment 5:
13. Find the first 7 terms of the Fibonacci series using 8085.
--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 05 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 content 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 –
MEMORY ADDRESS MNEMONICS COMMENT
Input
Address Data
9000H 01
Program
Output
Address Data
9000 01
9001 03
9002 05
9003 07
9004 09
9005 19
15. Find the factorial of a given number using 8085.
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
ADDRESS LABEL MNEMONIC COMMENT
1. BCD to HEX
2. HEX to BCD
3. HEX to ASCII
4. ASCII to HEX
1]. Program
HEX
Address Labels Mnemonics Comments
Codes
8011 E6, 0F ANI 0FH Mask of the most significant four bits
HEX
Address Labels Mnemonics Comments
Codes
8015 E6, F0 ANI F0H Mask of the least significant four bits
8018 0F RRC
8019 0F RRC
801A 0F RRC
F003 16, 00 MVI D,00H Clear D- reg for Most significant Byte
F007 C6, 01 LOOP ADI 01H Count the number one by one
2015 RLC
2016 RLC
2017 RLC
2018 RLC
MEMORY ADDRESS MNEMONICS COMMENTS
2025 HLT
JC SKIP
ADI 07H
RET
4].
Algorithm –
1. Input the content of 2050 in accumulator.
2. Subtract 30H from accumulator.
3. Compare the content of accumulator with 0AH.
4. If content of accumulator is less than 0A then goto step 6 else goto step 5.
5. Subtract 07H from accumulator.
6. Store content of accumulator to memory location 3050.
7. Terminate the program.
Program –
ADDRESS MNEMONICS COMMENTS
Assignment 7:
17. Display a number using LEDs to show the output.
Solution:
Control Word:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0 =80H
Program
A002 D3
OUT F3H Set port A in the output mode
A003 F3
A004 3E
Load the number to be displayed,
MVI A, 05H
05H into the accumulator
A005 05
A006 D3
OUT F0H Display the number at port A
A007 F0
A009 06
A01A A0
Output:
Four LEDs are connected with the output pins of the chip through a jumper. The first and the third LEDs
were ON while the other LEDs were OFF, i.e. the LEDs displayed the number O5H i.e. 0101. This is
basically, an Infinite loop. That is why the LEDs keep on displaying 05H until the microprocessor is reset.
If we would connect 4 more LEDs for the four most significant bits, these LEDs will remain OFF(this is not
done in the lab exp).
A000 3E
MVI A, 80H Load 80H in the accumulator.
A001 80
A002 D3
OUT F3H Set port A in the output mode
A003 F3
A004 3E
MVI A, FFH Load FFH in Accumulator
A005 FF
A007 F0
A009 00
A00A B0
A00C 00
A00E F0
A010 00
A011 B0
A012 C3 JMP
A014 A0
B001 02
B003 DE
B004 04
Address HEX Codes Mnemonics Comments
B007 02
B008 B0
Output:
Four LEDs are connected with the output pins of the chip through a Jumper. The LED is turned ON and
OFF periodically. This is basically an Infinite loop. That’s why this cycle repeats until the microprocessor is
reset.
UP Counter:
A011 DCR B 05
A016 INR A 3C
A018 RST 1
Down Counter: