Microprocessor Basics
Microprocessor Basics
MICROCONTROLLER-Lab3 Credits:2
30th January 2024
DELAYS
Delay = No. of T-States / Frequency
If there is 1 byte instruction we will require minimum 4T states.
If there is 2 byte instruction we will require minimum 7T states.
If there is 3 byte instruction we will require minimum 10T states.
For example a “MVI” instruction uses 7 T-States. Therefore, if the Microprocessor is running
at 2 MHz, the instruction would require 3.5 µSeconds to complete.
Consider a delay loop:
MVI C, FFH 7 T-States
LOOP DCR C 4 T-States
JNZ LOOP 10 T-States
The first instruction initializes the loop counter and is executed only once requiring only
7 T-States. The following two instructions form a loop that requires 14 T-States to execute
and is repeated 255 times until C becomes 0.
NESTED LOOPS FOR DELAY
STACK
● The stack is a reserved area of the memory in RAM where we can store
temporary information. Interestingly, the stack is a shared resource as it can be
shared by the microprocessor and the programmer. The programmer can use the
stack to store data. And the microprocessor uses the stack to execute subroutines.
● The 8085 has a 16-bit register known as the ‘Stack Pointer’. This register’s
function is to hold the memory address of the stack. This control is given to the
programmer. The programmer can decide the starting address of the stack by
loading the address into the stack pointer register at the beginning of a program.
● The stack works on the principle of Last In First Out (LIFO). The memory location
of the most recent data entry on the stack is known as the Stack Top.
STACK
● The stack normally grows backwards into memory. – In other words, the
programmer defines the bottom of the stack and the stack grows up into
reducing address range.
● Normally we place the bottom of the stack at the end of memory to keep it
as far away from user programs as possible.
STACK
● The stack is defined by setting the 16 bit SP (Stack Pointer) register.
● PUSH and POP are the two instructions used to manipulate the data in
the stack.
PUSH and POP
● Information is saved on the stack by PUSHing it on and it is retrieved from
the stack by POPing it off.
● The 8085 provides two instructions: PUSH and POP for storing
information on the stack and retrieving it back.
LXI H,1234
LXI D, 5678
LXI SP, FFFF
PUSH H
PUSH D
POP H
POP D
Programs for stack and
subroutines
2. Write a program that calculates the sum of 4 numbers from 4 registers. Let
the addition operation be considered as a subroutine program.
A - 01H
B - 02H
C - 03H
D - 04H
Program
LXI SP, FFFF
MVI A, 01H
MVI B, 02H
MVI C, 03H
MVI D, 04H
CALL ADD
HLT
ADD: ADD B
ADD C
ADD D
RET
Programs for stack and
subroutines
3. Write a subroutine program to add two numbers, call a delay, and subtract the two numbers using subroutine
programming.
Program
MVI A, 05H
MVI B, 03H
ADD B
MOV C, A
CALL DELAY
SUB B
MOV D, A
HLT