Mi 5 PDF
Mi 5 PDF
Mi 5 PDF
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
o
o
o
o
•
•
•
o
•
•
•
•
o
o
o
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
D6 D4 D3 D2 D1 D0
I7 I6 I5 IE 7.5 6.5 5.5
Serial Input
Data bit Interrupt
masked
if bit=1
•
•
•
•
•
•
•
•
•
•
Unit-5 – Assembly Language Program
1. Write an ALP to load register B with data 14H, register C with FFH, register D
with 29H and register E with 67H.
MVI B, 14H
MVI C, FFH
MVI D, 29H
MVI E, 67H
HLT
MOV C, B
HLT
MOV A, B
HLT
4. write an ALP which directly store data 56H into memory location 2050H.
LXI H, 2050H
MVI M, 56H
HLT
5. Write an 8085 assembly language program for exchanging two 8-bit numbers
stored in memory locations 2050h and 2051h.
LDA 2050H
MOV B, A
LDA 2051H
STA 2050H
MOV A, B
STA 2051H
HLT
MOV B, D
MOV C, E
MOV D, H
MOV E, L
HLT
MOV L, C
XCHG ; The contents of register H are exchanged with the contents of register D, and the
MOV B, H
MOV C, L
HLT
7. Write the set of 8085 assembly language instructions to store the contents of B
and C registers on the stack.
MVI B, 50H
MVI C, 60H
PUSH B
PUSH C
HLT
8. Write an ALP to delete (Make 00H) the data byte stored at memory location
from address stores in register DE.
MVI A, 00H
STAX D
HLT
9. Write an 8085 assembly language program to add two 8-bit numbers stored in
memory locations 2050h and 2051h. Store result in location 2052h.
LXI H 2050H
MOV A M
INX H
ADD M
MOV M A
HLT
10. Subtract 8 bit data stored at memory location 2050H from data stored at
memory location 2051H and store result at 2052H.
LXI H 2050H
MOV A M
INX H
SUB M ; A = A - M
INX H
MOV M A
HLT
11. Write an 8085 assembly language program to add two 16-bit numbers
stored in memory.
LHLD 2050H
XCHG ; The contents of register H are exchanged with the contents of register D, and the
LHLD 2052H
MOV A E
ADD L
MOV L A
MOV A D
ADC H
MOV H A
SHLD 2054H ; Store Value of L Register at 2054 and value of H register at 2055.
HLT
12. Write an 8085 assembly language program to find the number of 1’s binary
representation of given 8-bit number.
MVI B 00H
MVI C 08H
MOV A D
JNC SKIP
INR B
JNZ BACK
HLT
ORA C
ANA E
MOV D A
HLT
14. Write an 8085 assembly language program to add two decimal numbers
using DAA instruction.
LXI H 2050H
MOV A M
INX H
MOV B M
MVI C 00H
ADD B
JNC SKIP
INR C
MOV M A
INX H
MOV M C
HLT
MOV B A
LDA 2051H
CMP B
JNC SMALL
STA 2052H
HLT
SMALL: MOV A B
STA 2052H
HLT
16. Write an 8085 program to copy block of five numbers starting from
location 2001h to locations starting from 3001h.
LXI D 3100H
MVI C 05H
LXI H 2100
LOOP: MOV A M
STAX D
INX D
INX H
DCR C
JNZ LOOP
HLT
17. An array of ten data bytes is stored on memory locations 2100H onwards.
Write an 8085 assembly language program to find the largest number and
store it on memory location 2200H.
LXI H 2100H
MVI C 0AH
MOV A M
DCR C
LOOP: INX H
JNC AHED
MOV A M
AHED: DCR C
JNZ LOOP
STA 2200H
HLT
18. Write an 8085 assembly language program to add block of 8-bit numbers.
LXI H 2000H
LXI B 3000H
LXI D 4000H
BACK: LDAX B
ADD M
STAX D
INX H
INX B
INX D
MOV A L
CPI 0A
JNZ BACK
HLT
19. Write an 8085 assembly language program to count the length of string
ended with 0dh starting from location 2050h (Store length in register B).
LXI H 2050H
MVI B 00H
BACK: MOV A M
INR B
INX H
CPI 0DH
DCR B
HLT
20. An array of ten numbers is stored from memory location 2000H onwards.
Write an 8085 assembly language program to separate out and store the EVEN
and ODD numbers on new arrays from 2100H and 2200H, respectively.
LXI H 2000H
LXI D 2100H
LXI B 2200H
MVI A 0AH
MOV A M
ANI 01H
JNZ CARRY
MOV A M
STAX B
INX B
JMP JUMP
STAX D
INX D
DCR A
INX H
JNZ COUNTER
HLT
21. An array of ten data bytes is stored on memory locations 2100H onwards.
Write an 8085 assembly language program to find the bytes having
complemented nibbles (e.g. 2DH, 3CH, 78H etc.) and store them on a new array
starting from memory locations 2200H onwards.
LXI H 2100H
LXI D 2200H
LOOP: MOV A M
ANI 0FH
MOV B A
MOV A M
ANI F0H
RRC
RRC
RRC
RRC
CPM B
JNZ NEXT
MOV A M
STAX D
INX D
NEXT: INX H
DCR C
JNZ LOOP
HLT
22. Write an 8085 assembly language program to count the positive numbers,
negative numbers, zeros, and to find the maximum number from an array of
twenty bytes stored on memory locations 2000H onwards. Store these three
counts and the maximum number on memory locations 3001H to 3004H,
respectively.
LXI H 2000
MVI C 14
MVI D 00
MVI B 00
MVI E 00
LOOP: MOV A M
CMP B
JNZ POS
INX H
DCR C
JNZ LOOP
JMP STORE
INX H
DCR C
JNZ LOOP
JMP STORE
INX H
DCR C
JNZ LOOP
JMP STORE
STORE: MOV A E
STA 3001
MOV A D
STA 3002
LXI H 2000
MVI C 14
MVI D 00
MVI B 00
LOOP1: MOV A M ; Main Program for count Zero And Find Maximum.
CMP B
JZ ZERO
JNC MAX
INX H
DCR C
JNZ LOOP1
JMP STORE1
INX H
DCR C
JNZ LOOP1
JMP STORE1
JC SKIP
MOV E A
SKIP: INX H
DCR C
JNZ LOOP1
JMP STORE1
STA 3003
MOV A E
23. Write an 8085 assembly language program to separate out the numbers
between 2010 and 4010 from an array of ten numbers stored on memory
locations 2000H onwards. Store the separated numbers on a new array from
3000H onwards.
LXI H 2000
LXI D 3000
MVI C 0A
LOOP: MOV A M
CPI 14
JZ NEXT
JC NEXT
CPI 28
JNC NEXT
STAX D
INX D
DCR C
JNZ LOOP
HLT
24. Write an 8085 assembly language program sort an array of twenty bytes
stored on memory locations 2000H onwards in descending order.
MVI B 14
MVI C 13
L1: MOV A M
INX H
CMP M
JC SWAP
bACK: DCR C
JNZ L1
JNZ L2
HLT
MOV M A
DCX H
MOV M D
INX H
JMP BACK
MVI C 01H
LXI H 4101H
SHLD 3000H
LDA 4100H
STA 4200H
; This program fetch one by one value from original array and sore it on new array if it is not duplicate.
MOV A M
INX H
DCR B
JZ OVER
SHLD 3000H
LXI H 4200H
MOV D C
L2: CMP M
JZ L1
DCR D
JNZ L2
MOV M A
INR C
JMP L1
OVER: HLT
26. Write an ALP to Pack the two unpacked BCD numbers stored in memory
locations 2200H and 2201H and store result in memory location 2300H.
Assume the least significant digit is stored at 2200H.
LDA 2201
RLC
RLC
RLC
ANI F0
MOV C A
LDA 2200
ADD C
STA 2300
HLT
27. Write a set of 8085 assembly language instructions to unpack the upper
nibble of a BCD number.
MVI A 98
MOV B A
ANI F0
RRC
RRC
RRC
STA 2000
LXI D 1020
MOV A L
SUB E
DAA
STA 2000
MOV A H
SBB D
DAA
STA 2001
HLT
EI
CALL DELAY
JMP LOOP
HLT
DELAY: NOP
NOP
NOP
NOP
RET
OUT A0
JMP LOOP
REPEAT: OUT AC
MVI C Count
AGAIN: DCR C
JNZ AGAIN
CMA
JMP REPEAT
Calculation:
1
𝑇𝑖𝑚𝑒 𝑝𝑒𝑟𝑖𝑜𝑑 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒 𝑤𝑎𝑣𝑒 = = 0.4 ∗ 10−3 𝑠.
2.5 ∗ 103
0.4 ∗ 10−3 𝑠
𝑇𝑖𝑚𝑒 𝑝𝑒𝑟𝑖𝑜𝑑 𝑜𝑓 𝑢𝑝𝑝𝑒𝑟 ℎ𝑎𝑙𝑓 𝑎𝑛𝑑 𝑙𝑜𝑤𝑒𝑟 ℎ𝑎𝑙𝑓 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒 𝑤𝑎𝑣𝑒 = . = 0.2 ∗ 10−3 𝑠.
2
𝑙𝑒𝑡 𝑝𝑟𝑜𝑐𝑒𝑠𝑠𝑜𝑟 𝑡𝑖𝑚𝑒 𝑝𝑒𝑟𝑖𝑜𝑑 = 0.3 ∗ 10−6 𝑠.
0.2 ∗ 10−3
𝐷𝑒𝑙𝑎𝑦 𝑟𝑒𝑞𝑢𝑖𝑟𝑒𝑑 𝑏𝑒𝑤𝑒𝑒𝑛 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒 𝑤𝑎𝑣𝑒 = ≈ 666𝑇𝑠𝑡𝑎𝑡𝑒𝑠
0.3 ∗ 10−6
Now
658 = 14 ∗ 𝐶𝑜𝑢𝑛𝑡
𝐶𝑜𝑢𝑛𝑡 = 47
𝐶𝑜𝑢𝑛𝑡 = 2𝐹𝐻
Final Program:
MVI A 01H
REPEAT: OUT AC
MVI C 2F
AGAIN: DCR C
JNZ AGAIN
CMA
JMP REPEAT
1. Stack
Stack is a group of memory location in the R/W memory that is used for temporary storage of binary
information during execution of a program.
The starting memory location of the stack is defined in program and space is reserved usually at the high
end of memory map.
The beginning of the stack is defined in the program by using instruction LXI SP, 16-bit memory address.
Which loads a 16-bit memory address in stack pointer register of microprocessor.
Once stack location is defined storing of data bytes begins at the memory address that is one less then
address in stack pointer register. LXI SP, 2099h the storing of data bytes begins at 2098H and continues
in reversed numerical order.
Fig. Stack
Data bytes in register pair of microprocessor can be stored on the stack in reverse order by using the
PUSH instruction.
PUSH B instruction sore data of register pair BC on sack.
Data bytes can be transferred from the stack to respective registers by using instruction POP.
2. Subroutine
A subroutine is a group of instruction that performs a subtask of repeated occurrence.
A subroutine can be used repeatedly in different locations of the program.
Fig. Subroutine
Example: write ALP to add two numbers using call and subroutine.
LXI H 2000 ; Load memory address of operand
MOV B M ; Store first operand in register B
INX H ;Increment H-L pair
MOV A M ; Store second operand in register A
CALL ADDITION ; Call subroutine ADDITION
STA 3000 ; Store answer
HLT
4. Counters
A counter is designed simply by loading appropriate number into one of the registers and using INR or
DNR instructions.
Loop is established to update the count.
Each count is checked to determine whether it has reached final number; if not, the loop is repeated.
Fig. Counter
5. Time Delay
Each instruction passes through different combinations of Fetch, Memory Read, and Memory Write
cycles.
Knowing the combinations of cycles, one can calculate how long such an instruction would require to
complete.
It is counted in terms of number of T–states required.
Calculating this time we generate require software delay.
9. Code Conversion
Two Digit BCD Number to Binary Number
1. Initialize memory pointer to given address (2000).
2. Get the Most Significant Digit (MSD).
3. Multiply the MSD by ten using repeated addition.
4. Add the Least Significant Digit (LSD) to the result obtained in previous step.
5. Store the HEX data in Memory.
Program
LXI H 2000
MOV C M
MOV A C
ANI 0F ; AND operation with 0F (00001111)
MOV E A
MOV A C
ANI F0 ; AND operation with F0 (11110000)
JZ SB1 ; If zero skip further process and directly add LSD
RRC ; Rotate 4 times right
RRC
RRC
RRC
MOV D A
MVI A 00
L1: ADI 0A ; Loop L1 multiply MSD with 10
DCR D
JNZ L1
SB1: ADD E
STA 3000 ; Store result
HLT
SUB1: CPI 0A
JC SKIP
ADI 07
SKIP: ADI 30
RET ; Return Subroutine
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
BIU (Bus Interface Unit)
•
•
•
•
•
•
•
•
EU (Execution Unit)
Components of EU
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
opcode address
•
•
•
call printf
be Loop
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•