Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Mi 5 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 116










































































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

2. Write an ALP to transfer data from register B to C.


MVI B, 55H

MOV C, B

HLT

3. Write an ALP to store data of register B into memory location 2050H.


MVI B, 67H

MOV A, B

STA 2050H ; Store data of Accumulator at memory location 2050H

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

6. Write an ALP to interchange 16-bit data stored in register BC and DE.


WITHOUT XCHG INSTRUCTION
MOV H, B

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 1


Unit-5 – Assembly Language Program
MOV L, C

MOV B, D

MOV C, E

MOV D, H

MOV E, L

HLT

WITH XCHG INSTRUCTION


MOV H, B

MOV L, C

XCHG ; The contents of register H are exchanged with the contents of register D, and the

; contents of register L are exchanged with the contents of register E.

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 2


Unit-5 – Assembly Language Program
INX H

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

; contents of register L are exchanged with the contents of register E.

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 3


Unit-5 – Assembly Language Program
BACK: RAR ; Rotate Accumulator Right through carry flag.

JNC SKIP

INR B

SKIP: DCR C ; Increment of B will skip.

JNZ BACK

HLT

13. Implement the Boolean equation D= (B+C) ∙ E, where B, C, D and E


represents data in various registers of 8085.
MOV A B

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

DAA ; Decimal adjustment of accumulator.

JNC SKIP

INR C

SKIP: INX H ; Increment of C will skip.

MOV M A

INX H

MOV M C

HLT

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 4


Unit-5 – Assembly Language Program
15. Write an 8085 assembly language program to find the minimum from two
8-bit numbers.
LDA 2050H

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 5


Unit-5 – Assembly Language Program
CMP M ; Compare Data of accumulator with the data of memory location specified by HL pair and

; set flags accordingly.

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 6


Unit-5 – Assembly Language Program
JNZ BACK

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

COUNTER: STA 3000H

MOV A M

ANI 01H

JNZ CARRY

MOV A M

STAX B

INX B

JMP JUMP

CARRY: MOV A M ; This block will store Odd numbers.

STAX D

INX D

JUMP: LDA 3000H

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 7


Unit-5 – Assembly Language Program
MVI C 0AH

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 8


Unit-5 – Assembly Language Program
JC NEG

JNZ POS

INX H

DCR C

JNZ LOOP

JMP STORE

NEG: INR D ; Count Negative number

INX H

DCR C

JNZ LOOP

JMP STORE

POS: INR E ; Count Positive number

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

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 9


Unit-5 – Assembly Language Program
MVI E 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

ZERO: INR D ; For count Zero

INX H

DCR C

JNZ LOOP1

JMP STORE1

MAX: CMP E ; Find Maximum.

JC SKIP

MOV E A

SKIP: INX H

DCR C

JNZ LOOP1

JMP STORE1

STORE1: MOV A D ; Store Number of zeros

STA 3003

MOV A E

STA 3004 ; Store maximum.

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 10


Unit-5 – Assembly Language Program
HLT

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

NEXT: INX H ; Skip Storing of Number.

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

L2: LXI H 2000

MVI C 13

L1: MOV A M

INX H

CMP M

JC SWAP

bACK: DCR C

JNZ L1

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 11


Unit-5 – Assembly Language Program
DCR B

JNZ L2

HLT

SWAP: MOV D M; This block swap values.

MOV M A

DCX H

MOV M D

INX H

JMP BACK

25. An array of twenty data bytes is stored on memory locations 4100H


onwards. Write an 8085 assembly language program to remove the duplicate
entries from the array and store the compressed array on a new array starting
from memory locations 4200H onwards.
MVI B 14H

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.

L1: LHLD 3000H

MOV A M

INX H

DCR B

JZ OVER

SHLD 3000H

LXI H 4200H

MOV D C

L2: CMP M

JZ L1

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 12


Unit-5 – Assembly Language Program
INX H

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 ; Rotate accumulator left 4 times without carry.

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 ; Rotate accumulator left 4 times without carry.

RRC

RRC

RRC

STA 2000

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 13


Unit-5 – Assembly Language Program
HLT

28. Write Assembly language program to subtract 2 16-bit BCD numbers.


LXI H 3040

LXI D 1020

MOV A L

SUB E

DAA

STA 2000

MOV A H

SBB D

DAA

STA 2001

HLT

29. Write an 8085 assembly language program to continuously read an input


port with address 50H. Also write an ISR to send the same data to output port
with address A0H when 8085 receives an interrupt request on its RST 5.5 pin.
LOOP: IN 50

EI

CALL DELAY

JMP LOOP

HLT

DELAY: NOP

NOP

NOP

NOP

RET

; This code must be write at memory location 002C onwards.

OUT A0

JMP LOOP

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 14


Unit-5 – Assembly Language Program
30. Write an ALP to generate a square wave of 2.5 kHz frequency. Use D0 bit of
output port ACH to output the square wave.
MVI A 01H

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

666 = 7 + (14 ∗ 𝐶𝑜𝑢𝑛𝑡) − 3 + 4

658 = 14 ∗ 𝐶𝑜𝑢𝑛𝑡

𝐶𝑜𝑢𝑛𝑡 = 47

𝐶𝑜𝑢𝑛𝑡 = 2𝐹𝐻

Final Program:

MVI A 01H

REPEAT: OUT AC

MVI C 2F

AGAIN: DCR C

JNZ AGAIN

CMA

JMP REPEAT

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 15


Unit-5 – Assembly Language Program

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 16


Unit-6 – Stack & Subroutines

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.

Fig. PUSH operation on stack

Data bytes can be transferred from the stack to respective registers by using instruction POP.

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 1


Unit-6 – Stack & Subroutines

Fig. POP operation on stack

Instruction necessary for stack in 8085


LXI SP, 2095 Load the stack pointer register with a 16-bit address.
PUSH B/D/H It copies contents of B-C/D-E/H-L register pair on the stack.
PUSH PSW Operand PSW represents Program status word meaning contents of accumulator and flags.
POP B/D/H It copies content of top two memory locations of the stack in to specified register pair.
POP PSW It copies content of top two memory locations of the stack in to B-C accumulator and flags
respectively.

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.

Advantage of using Subroutine


Rather than repeat the same instructions several times, they can be grouped into a subroutine that is
called from the different locations.

Where to write Subroutine?


In Assembly language, a subroutine can exist anywhere in the code.
However, it is customary to place subroutines separately from the main program.

Instructions for dealing with subroutines in 8085.


The CALL instruction is used to redirect program execution to the subroutine.
o When CALL instruction is fetched, the Microprocessor knows that the next two new Memory
location contains 16bit subroutine address.
o Microprocessor Reads the subroutine address from the next two memory location and stores the
higher order 8bit of the address in the W register and stores the lower order 8bit of the address in
the Z register.
o Push the Older address of the instruction immediately following the CALL onto the stack [Return
address]
o Loads the program counter (PC) with the new 16-bit address supplied with the CALL instruction from
WZ register.
The RET instruction is used to return.

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 2


Unit-6 – Stack & Subroutines
Number of PUSH and POP instruction used in the subroutine must be same, otherwise, RET instruction
will pick wrong value of the return address from the stack and program will fail.

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

ADDITION: ADD B ; Add A and B


RET ; Return

Conditional call and return instruction available in 8085


CC 16-bit address Call on Carry, Flag Status: CY=1
CNC 16-bit address Call on no Carry, Flag Status: CY=0
CP 16-bit address Call on positive, Flag Status: S=0
CM 16-bit address Call on minus, Flag Status: S=1
CZ 16-bit address Call on zero, Flag Status: Z=1
CNZ 16-bit address Call on no zero, Flag Status: Z=0
CPE 16-bit address Call on parity even, Flag Status: P=1
CPO 16-bit address Call on parity odd, Flag Status: P=0
RC Return on Carry, Flag Status: CY=1
RNC Return on no Carry, Flag Status: CY=0
RP Return on positive, Flag Status: S=0
RM Return on minus, Flag Status: S=1
RZ Return on zero, Flag Status: Z=1
RNZ Return on no zero, Flag Status: Z=0
RPE Return on parity even, Flag Status: P=1
RPO Return on parity odd, Flag Status: P=0

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 3


Unit-6 – Stack & Subroutines

3. Applications of Counters and Time Delays


1. Traffic Signal
2. Digital Clocks
3. Process Control
4. Serial data transfer

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.

Time Delay Using Single Register


Label Opcode Operand Comment T-states
MVI C,05h ; Load Counter 7
LOOP: DCR C ; Decrement Counter 4
JNZ LOOP ; Jump back to Decr. C 10/7

MVI C 05 DCR C JNZ LOOP (true) JNZ LOOP (false)


Mchine Cycle: F + R = 2 Mchine Cycle: F = 1 Mchine Cycle: F + R + R = 3 Mchine Cycle: F + R = 3
T-States: 4T + 3T = 7T T-States: 4T = 4T T-States: 4T + 3T + 3T = 10T T-States: 4T + 3T = 7T

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 4


Unit-6 – Stack & Subroutines
Instruction MVI C, 05h requires 7 T-States to execute. Assuming, 8085 Microprocessor with 2MHz clock
frequency. How much time it will take to execute above instruction?
Clock frequency of the system (f) = 2 MHz
Clock period (T) = 1/f = ½ * 10-6 = 0.5 µs
Time to execute MVI = 7 T-states * 0.5 µs
= 3.5 μs
Now to calculate time delay in loop, we must account for the T-states required for each instruction, and
for the number of times instructions are executed in the loop. There for the next two instructions:
DCR: 4 T-States
JNZ: 10 T-States
14 T-States
Here, the loop is repeated for 5 times.
Time delay in loop TL with 2MHz clock frequency is calculated as:
TL= T * Loop T-sates * N10 -----------------(1)
TL : Time Delay in Loop
T : Clock Frequency
N10 : Equivalent decimal number of hexadecimal count loaded in the delay register.
Substituting value in equation (1)
TL= (0.5 * 10-6 * 14 * 5)
= 35 s
If we want to calculate delay more accurately, we need to accurately calculate execution of JNZ
instruction i.e
If JNZ = true, then T-States = 10
Else if JNZ =false, then T-States = 7
Delay generated by last clock cycle:
= 3T * Clock Period
= 3T * (1/2 * 10-6 )
= 1.5 s
Now, the accurate loop delay is:
TLA=TL - Delay generated by last clock cycle
TLA= 35 s - 1.5 s
TLA= 33.5 s
Now, to calculate total time delay
Total Delay = Time taken to execute instruction outside loop + Time taken to execute loop instructions
TD = TO + TLA
= (7 * 0.5 s) + 33.5 s
= 3.5 s + 33.5 s
= 37 s
In most of the case we are given time delay and need to find value of the counter register which decide
number of times loop execute.
For example: write ALP to generate 37 µs delay given that clock frequency if 2 MHz.
Single register loop can generate small delay only for large delay we use other technique.

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 5


Unit-6 – Stack & Subroutines
Time Delay Using a Register Pair
Time delay can be considerably increased by setting a loop and using a register pair with a 16-bit number
(FFFF h).
A 16-bit is decremented by using DCX instruction.
Problem with DCX instruction is DCX instruction doesn’t set Zero flag.
Without test flag, Jump instruction can’t check desired conditions.
Additional technique must be used to set Zero flag.

Label Opcode Operand Comment T-states


LXI B,2384 h ; Load BC with 16-bit counter 10
LOOP: DCX B ; Decrement BC by 1 6
MOV A, C ; Place contents of C in A 4
ORA B ; OR B with C to set Zero flag 4
JNZ LOOP ; if result not equal to 0, 10/7 jump back to loop 10/7
Here the loop includes four instruction:
Total T-States = 6T + 4T + 4T + 10T
= 24 T-states
The loop is repeated for 2384 h times.
Converting (2384)16 into decimal.
2384 h = (2 * 163 )+ (3* 162) + (8 * 161) + (4 * 160)
= 8192 + 768 + 128 + 4 = 9092
Clock frequency of the system (f)= 2 MHz
Clock period (T) = 1/f = ½ * 10-6 = 0.5 s
Now, to find delay in the loop
TL= T * Loop T-sates * N10
= 0.5 * 24 * 9092
= 109104 s = 109 ms (without adjusting last cycle)

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 6


Unit-6 – Stack & Subroutines
Time Delay Using a LOOP within a LOOP

Fig. Time Delay Using a LOOP within a LOOP

Label Opcode Operand T-states


MVI B,38h 7T
LOOP2: MVI C,FFh 7T
LOOP1: DCR C 4T
JNZ LOOP1 10/7 T
DCR B 4T
JNZ LOOP2 10/7 T
Calculating delay of inner LOOP1: TL1
TL= T * Loop T-states * N10
= 0.5 * 14* 255
= 1785 μs = 1.8 ms
TL1= TL – (3T states* clock period)
= 1785 – ( 3 * ½ * 10-6)
= 1785-1.5=1783.5 μs
Now, Calculating delay of outer LOOP2: TL2
Counter B : (38)16 = (56)10 So loop2 is executed for 56 times.
T-States = 7 + 4 + 10 = 21 T-States
TL2 = 56 (TL1 + 21 T-States * 0.5)
= 56( 1783.5 μs + 10.5)

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 7


Unit-6 – Stack & Subroutines
= 100464 μs
TL2 = 100.46 ms

Disadvantage of using software delay


Accuracy of time delay depends on the accuracy of system clock.
The Microprocessor is occupied simply in a waiting loop; otherwise it could be employed to perform
other functions.
The task of calculating accurate time delays is tedious.
In real time applications timers (integrated timer circuit) are commonly used.
Intel 8254 is a programmable timer chip that can be interfaced with microprocessor to provide timing
accuracy.
The disadvantage of using hardware chip include the additional expense and the need for extra chip in
the system.

6. Counter design with time delay

Fig. 6. Counter design with time delay

It is combination of counter and time delay.


I consist delay loop within counter program.

7. Hexadecimal counter program


Write a program to count continuously in hexadecimal from FFh to 00h with 0.5 s clock period. Use
register C to set up 1 ms delay between each count and display the number at one of the output port.
Given:
Counter= FF h
Clock Period T=0.5 s

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 8


Unit-6 – Stack & Subroutines
Total Delay = 1ms
Output:
To find value of delay counter
Program
MVI B,FF
LOOP:MOV A,B
OUT 01
MVI C, COUNT; need to calculate delay count
DELAY: DCR C
JNZ DELAY
DCR B
JNZ LOOP
HLT
Calculate Delay for Internal Loop
TI = T-States * Clock Period * COUNT
= 14 * 0.5 * 10-6 * COUNT
TI = (7.0 * 10-6 )* COUNT
Calculate Delay for Outer Loop:
TO = T-States * Clock Period
= 35 * 0.5 * 10-6

Calculate Total Time Delay:


TD = TO + TL
1 ms = 17.5 * 10-6 + (7.0 * 10-6 )* COUNT
1 * 10-3 = 17.5 * 10-6 + (7.0 * 10-6 )* COUNT
COUNT="1 ∗ 10−3 − 17.5 ∗ 10−6" /"7.0 ∗ 10−6"
COUNT= (140)10 = (8C)16

8. 0-9 up/down counter program


Write an 8085 assembly language program to generate a decimal counter (which counts 0 to 9
continuously) with a one second delay in between. The counter should reset itself to zero and repeat
continuously. Assume a crystal frequency of 1MHz.
Program
START: MVI B,00H
DISPLAY: OUT 01
LXI H, COUNT
LOOP: DCX H
MOV A, L
ORA H
JNZ LOOP
INR B
MOV A,B
CPI 0A
JNZ DISPLAY

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 9


Unit-6 – Stack & Subroutines
JZ START

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

8-bit Binary Number to Decimal Number


1. Load the binary data in accumulator
2. Compare ‘A’ with 64 (Dicimal 100) if cy = 01, go step 5 otherwise next step
3. Subtract 64H from ‘A’ register
4. Increment counter 1 register
5. Go to step 2
6. Compare the register ‘A’ with ‘0A’ (Dicimal 10), if cy=1, go to step 10, otherwise next step
7. Subtract 0AH from ‘A’ register
8. Increment Counter 2 register
9. Go to step 6
10. Combine the units and tens to from 8 bit result
11. Save the units, tens and hundred’s in memory
12. Stop the program execution
Program
MVI B 00

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 10


Unit-6 – Stack & Subroutines
LDA 2000
LOOP1: CPI 64 ; Compare with 64H
JC NEXT1 : If A is less than 64H then jump on NEXT1
SUI 64 ; subtract 64H
INR B
JMP LOOP1
NEXT1: LXI H 2001
MOV M B ; Store MSD into memory
MVI B 00
LOOP2: CPI 0A ; Compare with 0AH
JC NEXT2 ; If A is less than 0AH then jump on NEXT2
SUI 0A ; subtract 0AH
INR B
JMP LOOP2
NEXT2: MOV D A
MOV A B
RLC
RLC
RLC
RLC
ADD D
STA 2002 ; Store packed number formed with two leas significant digit
HLT

Binary Number to ASCII Number


Load the given data in A - register and move to B - register
Mask the upper nibble of the Binary decimal number in A - register
Call subroutine to get ASCII of lower nibble
Store it in memory
Move B - register to A - register and mask the lower nibble
Rotate the upper nibble to lower nibble position
Call subroutine to get ASCII of upper nibble
Store it in memory
Terminate the program.
LDA 5000 Get Binary Data
MOV B, A
ANI 0F ; Mask Upper Nibble
CALL SUB1 ; Get ASCII code for upper nibble
STA 5001
MOV A, B
ANI F0 ; Mask Lower Nibble
RLC
RLC
RLC
RLC
CALL SUB1 ; Get ASCII code for lower nibble
STA 5002

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 11


Unit-6 – Stack & Subroutines
HLT ; Halt the program.

SUB1: CPI 0A
JC SKIP
ADI 07
SKIP: ADI 30
RET ; Return Subroutine

ASCII Character to Hexadecimal Number


1. Load the given data in A - register
2. Subtract 30H from A - register
3. Compare the content of A - register with 0AH
4. If A < 0AH, jump to step6. Else proceed to next step
5. Subtract 07H from A - register
6. Store the result
7. Terminate the program
Program
LDA 2000
CALL ASCTOHEX
STA 2001
HLT

ASCTOHEX: SUI 30 ; This block Convert ASCII to Hexadecimal.


CPI 0A
RC
SUI 07
RET

10. BCD Arithmetic


Add 2 8-bit BCD Numbers
1. Load firs number into accumulator.
2. Add second number.
3. Apply decimal adjustment to accumulator.
4. Store result.
Program
LXI H, 2000H
MOV A, M
INX H
ADD M
DAA
INX H
MOV M, A
HLT

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 12


Unit-6 – Stack & Subroutines
Subtract the BCD number stored in E register from the number stored in the D
register
1. Find 99’s complement of data of register E
2. Add 1 to find 100’s complement of data of register E
3. Add Data of Register D
4. Apply decimal adjustment
Program
MVI A, 99H
SUB E : Find the 99's complement of subtrahend
INR A : Find 100's complement of subtrahend
ADD D : Add minuend to 100's complement of subtrahend
DAA : Adjust for BCD
HLT : Terminate program execution

11. 16-Bit Data operations


Add Two 16 Bit Numbers
1. Initialize register C for using it as a counter for storing carry value.
2. Load data into HL register pair from one memory address (9000H).
3. Exchange contents of register pair HL with DE.
4. Load second data into HL register pair (from 9002H).
5. Add register pair DE with HL and store the result in HL.
6. If carry is present, go to 7 else go to 8.
7. Increment register C by 1.
8. Store value present in register pair HL to 9004H.
9. Move content of register C to accumulator A.
10. Store value present in accumulator (carry) into memory (9006H).
11. Terminate the program.
Program
MVI C, 00H
LHLD 9000H
XCHG ; Exchange contents of register pair HL with DE
LHLD 9002H
DAD D ; Add register pair DE with HL and store the result in HL
JNC AHEAD ; If carry is present, go to AHEAD
INR C
AHEAD: SHLD 9004H ; Store value present in register pair HL to 9004H
MOV A, C
STA 9006H ; Store value present in accumulator (carry) into memory (9006H)
HLT

Subtract Two 16 Bit Numbers


1. Load first data from Memory (9000H) directly into register pair HL.
2. Exchange contents of register pair DE and HL.
3. Load second data from memory location (9002H) directly into register pair HL.

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 13


Unit-6 – Stack & Subroutines
4. Move contents of register E into accumulator A.
5. Subtract content of register L from A.
6. Move contents of accumulator A into register L.
7. Move contents of register D into accumulator A.
8. Subtract with borrow contents of register H from accumulator A.
9. Move contents of accumulator A into register H.
10. Store data contained in HL register pair into memory (9004H).
11. Terminate the program.
Program
LHLD 9000H ; Load first data from Memory (9000H) directly into register pair HL
XCHG ; Exchange contents of register pair DE and HL.
LHLD 9002H ; Load second data from memory location (9002H) directly into register pair HL
MOV A, E
SUB L
MOV L, A
MOV A, D
SBB H ; Subtract with borrow contents of register H from accumulator A
MOV H, A
SHLD 9004H ; Store data contained in HL register pair into memory (9004H)
HLT

Prof. Vijay M. Shekhat, CE Department | 2150707 – Microprocessor and Interfacing 14













































BIU (Bus Interface Unit)









EU (Execution Unit)
Components of EU




























































































Figure:80386 General Purpose, Index and Pointer Register




Figure:80386 Instruction Pointer and Flag Register
























































































opcode reg1,reg2,reg3 !reg1 op reg2 -> reg3


opcode reg1,const13,reg3 !reg1 op const13 -> reg3





add %L1,%L2,%L3 !%L1+%L2->%L3


opcode [reg1+reg2],reg3
opcode [reg1+const13],reg3


ld [%L1+%L2],%L3 !word at address [%L1+%L2]->%L3

opcode address



call printf
be Loop




























You might also like