Skip to content
The Computer Science
TheCScience
  • Engineering Subjects
    • Human Values
    • Computer System Architecture
    • Digital Communication
    • Internet of Things
  • NCERT Solutions
    • Class 12
    • Class 11
  • HackerRank solutions
    • HackerRank Algorithms Problems Solutions
    • HackerRank C solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
The Computer Science
TheCScience

Time Delay in Microprocessor

YASH PAL, March 23, 2026March 23, 2026

Time Delay in Microprocessor – In real-time applications, such as traffic light control, digital clock, process control, and serial communication, it is important to keep track of time. In some applications, a time delay is required between the execution of two instructions. There are two techniques to design the time delay in a microprocessor.

  1. Hardware technique
  2. Software technique

For the hardware time delay technique, additional hardware like 8253/8254 (Programmable Interval Timer) is required. The hardware technique has the advantages like it is very accurate. It can be used for real-time applications and frees the microprocessor to perform other tasks at the same time. The fundamental limitation of the hardware technique is the cost.

In the software time delay technique, no additional hardware is required, so it is cheaper than the hardware technique. But it has some limitations, like it is not accurate, makes the microprocessor busy for the entire delay period, etc. The tedious calculation is required to decide the count. The following methods are used to provide a time delay using a software technique.

  1. Using the NOP instruction
  2. Using counter
  3. Using a nested loop

Time Delay using NOP Instruction

Meaning of instruction NOP is NO operation. This instruction does nothing but simply makes the microprocessor busy for 4T states. So by executing a NOP instruction in between two instructions, a delay of 4T states may be provided.

                    1
1T-state = ___________________
           Operating frequency

Let’s take an example question to understand the time delay using the NOP instruction

Question – How many times does the instruction NOP have to be executed to provide a time delay of 1m sec? between two instructions. The crystal frequency is 4MHz.

Solution – Given that
Crystal frequency = 4MHz
Hence, the operating frequency (f) = 1/2 (Crystal frequency)
= 4/2 MHz
= 2MHz
Time required to execute NOP instruction = 4T
= 4(1/f)
= 4/(2 x 106) sec.
= 2μ sec.

Number of times the instruction NOP has to be executed to provide a time delay of 1m sec. between two instructions is (1m sec)/(2μ sec) = 500 times. From the above example solution, it is clear that the provided delay using the NOP instruction is not a good solution. This is because the programmer has to store a large number of NOP instructions in memory.

Time Delay using Counter

A counter can be used to provide the time delay. According to this technique, a counter is initialized with the desired value and decremented by one. This looping operation continues till the count value reaches zero. Since the execution times of the instructions used in a counting are known, the initial value of the counter can be determined. The counter can be designed by using a register (8-bit counter) or a register pair (16-bit counter). The figure below shows the flow chart for time delay using a counter.

Flowchart for time delay using counter
Flowchart for time delay using a counter

Using One Register (8-bit counter)

LableInstruction
Opcode
Instruction
Operand
CommentsMachine
Cycles
No. of T-states
MMC, nLoad the count of register C.OF + MR4T + 3T = 7T
LOOPDCRCDecrement counterOF4T
JNZLOOPIf the count is not zero, go to the location loopOF + MR + MR10/7T
Using one Register (8-bit counter)

Here, OF = Opcode Fetch and MR = Memory Read

The instruction JNZ is a three-byte instruction. The number of T-states for the JNZ instruction is shown as 10/7 in the program. It means that the microprocessor 8085 requires 10T-states to execute the instruction when the condition is true. But when the condition is false, the loop is terminated, requiring only 7T states. Time delay in the 8-bit counter using one register is given as below:

TDelay = 7T + (n-1)(4T + 10T) + (4T + 7T)
= 7T + 14nT - 14T + 11T
= 7T + 14nT - 3T
TDelay = 4T + 14nT

Let’s take an example question to understand the time delay using a one-register (8-bit Counter)

Question – Find the maximum time delay that can be provided using one register. The operating frequency of the microprocessor is 2MHz.

Solution – For the maximum time delay, the count value must be maximum. The maximum count value can be FFH or 25510 using one register. Therefore, the maximum time delay is given as follows:

TDelay = 4T + 14nT
= (4 x ( 1/(2×106)) + ((14×255)/(2×106)) sec.
= 1.785m sec.

Using Register Pair (16-bit Counter)

The maximum time delay (1.785 sec.), which can be introduced between two instructions using one register, is not sufficient for some applications. In those applications, we need to initialize the counter more than FFH or 255. Hence, a counter using a register pair instead of one register is used.

LabelInstruction
Opcode
Instruction
Operand
CommentsMachine
Cycles
No. of T-states
LXID, NLoad counter with 16-bit number NOF + MR + MR4T+3T+3T = 10T
LOOPDCXDDecrement counterOF6T
MOVA, ECopy the contents of register E to register AOF4T
ORADLogically OR the contents of register A and register D to check the counterOF4T
JNZLOOPRepeat until the DE register pair reaches zero.OF + MR + MR10/7T
Using a register pair (16-bit counter)

Here, OF = Opcode Fetch and MR = Memory Read.

In the above program, the DCX instruction is used to decrement the contents of the DE register pair. This instruction has 6T states in its opcode fetch machine cycle and does not affect any flag. When the contents of the DE register pair reach zero, the zero flag remains unchanged. Therefore, another technique is used to affect the zero flag as shown in programming by performing an ORing operation between the lower and higher pair, as shown below:

TDelay = 10T + (N-1)(6T + 4T + 4T + 10T) + (6T + 4T + 4T + 7T)
= 10T + 24NT - 24T + 21T
TDelay = 7T + 24NT

Let’s take an example question to understand the time delay using the Register Pair (16-bit Counter)

Question – Write a program to generate a delay of 0.4 sec. If the crystal frequency is 5MHz.

Solution – In the 8085 microprocessor, the operating frequency is half of the crystal frequency, hence
Operating frequency (f) = (5 x 106)/2 Hz = 2.5MHz
Time for one T-state = 1/(2.5 x 106) sec = 0.4μ sec
Now, we know TDelay = 7T + 24NT for 16-bit counter
N = ((TDelay – 7T)/24T) = (0.4 – 7 x 0.4 x 10-6)/(24 x 0.4 x 10-6) =4166610 or A2C2H

The value of count is 4166610 or A2C2H. The delay loop using a 16-bit counter will be as follows:

LabelInstruction
Opcode
Instruction
Operand
Comment
LXID, A2C2HLoad the counter with a 16-bit number A2C2H.
LOOPDCXDDecrement counter.
MOVA, ECopy the contents of register E to register A.
ORADLogically OR the contents of register A and register D to check the counter.
JNZLOOPRepeat until the DE register pair reaches zero.

Using nested Loop

This technique is also known as time delay using a loop within a loop. In this, there is more than one loop. The outer loop sets the count to repeat the delay provided by the inner loop. A flowchart for time delay using a nested loop is shown in the figure below.

Time delay using nested loop
Time delay using a nested loop
LabelInstruction
Opcode
Instruction
Operand
CommentsMachine
Cycles
No. of T-states
MMB, NoutLoad the outer counterOF + MR4T + 3T = 7T
MMC, NinLoad the inner counterOF + MR4T + 3T = 7T
LOOP2DCRCDecrement the inner counterOF4T
LOOP1JNZLOOP1If not zero goto LOOP1OF + MR + MR10T / 7T
DCRBDecrement the outer counterOF4T
JNZLOOP2If not zero goto LOOP2OF + MR +MR10T/7T

Let’s take an example program to understand time delay using a nested loop.

Question – Write a program to count continuously in hexadecimal from FFH to 00H in a system with a 0.5μ sec. clock period. Use register C to set up a 1m sec. Delay between each count and display the numbers at one of the output ports. Also, show the delay calculation.

Solution – The program has two parts; first is to design a given delay of 1m sec. between two counts, and the second is to set up a continuous down counter from FFH to 00H.

Delay Calculation: The required delay is 1m sec. which is less than the maximum delay provided by using one register (1.785m sec.). Hence, the delay counter can be designed with one register.
TDelay = 4T + 14nT
= 1 x 10-3 = (4 + 14n) x 0.5 x 10-6
= n = 142.610 ≃ 14310
= 8FH

Let the accumulator be used as a counter to display, and register C is used as a counter for the delay loop. The following algorithm is used to design the counter.

Algorithm:

Step 1: Initialize the counter (accumulator) with FFH to display.
Step 2: Display the value of the accumulator.
Step 3: Provide a desired delay.
Step 4: Decrement the counter and go to step 2.

Flowchart for Hexadecimal Counter with Delay of 1m sec

The assembly language program is given below for this problem.

Memory
Address
Hex
Code
LabelInstruction
Opcode
Instruction
Operand
Comments
XX00H
XX01H
3E
FF
MMA, FFHInitialize the display counter
XX02H
XX03H
D3
Port #
RPT
OUTPort #Display the contents of the accumulator at port #
XX04H
XX05H
0E
8F
MMC, 8FHInitialize the delay counter
XX06H0DLOOPDCRCDecrement the delay counter
XX07H
XX08H
XX09H
C2
06
XX
JNZLOOPIf not zero, goto memory location LOOP
XX0AH3DDCRADecrement the display counter
XX0BH
XX0CH
XX0DH
C3
02
XX
JMPRPTJump to location RPT
Assembly Language Program
engineering subjects Microprocessor microprocessor

Post navigation

Previous post
Next post

TheCScience

We at TheCScience.com are working towards the goal to give free education to every person by publishing in dept article about Secondary, Senior-Secondary, and Graduation level subjects.

Pages

About US

Contact US

Privacy Policy

DMCA

Our Tools

Hosting - get 20% off

Engineering Subjects

Internet of Things

Human Values

Digital Communication

Computer System Architecture

Programming Tutorials

Data Structure and Algorithm

C

Java

NCERT

Class 12th

©2026 TheCScience | WordPress Theme by SuperbThemes