Stack Operation and Sub Routine [In 8085 Microprocessor]

Definition of Stack in 8085 Microprocessor

Stack is a memory location/block which can be read or written at a single point called as Top of the stack (TOS).

Learn Microprocessor[Beginner to Advanced]


Stack-Operation-Sub-Routine-In-8085


Stack Operation in 8085  Microprocessor:

A 16-bit register is used for stack operation. It points to the Top of the Stack (TOS). To work with the stack, first of all the address of the stack should be loaded into SP(Stack Pointer).
For example:

  • LXI  SP, 16-bit address
There are two operations in stack. They are :
  1. PUSH Operation
  2. POP  Operation
A. PUSH Operation:
It refers to the insertion of data item into the stack.
Syntax: PUSH RP [RP = Register Pair]
  • PUSH B
  • PUSH D
For example:
LXI SP, 2099H
MVI H, 42H
MVI L, F2H
PUSH H

B. POP Operation:
It refers to the removal of data item from the stack. 
Syntax: POP RP
  • POP B
  • POP D

Sub Routine in 8085 Microprocessor

So what is a Sub Routine ? | Definition of Sub Routine

A Sub Routine is a group of instructions to perform arithmetic and other time delay operation. 
  • Subroutine resides in the memory block as separate unit from main program. A Sub routine in assembly language is similar to equivalent to the function in high level language.
  • Call of sub routine requires to transfer program counter to first address of sub routine. 
  • During this control transfer calling program need to be saved in stack. 
  • Last statement of any sub routine is Return statement. The execution of return statement transfer control to next instruction of calling program by reloading PC(Program Counter) with previously stored values.
  • The use of sub routine increases overhead in program but often prefer by programmers for modularity.
  • In 8085, CALL and RET are instructions for sub routine.

Conditional Call Instructions
Mnemonics Description
CC 16-bit address Call Sub Routine on Carry(CF=1)
CNC 16-bit address Call Sub Routine on No Carry(CF=0)
CZ 16-bit address Call on Zero(Z=1)
CNZ 16-bit address Call on No Zero(Z=0)
CM 16-bit address Call on Minus(SF=1)
CP 16-bit address Call on Plus(SF=0)
CPE 16-bit address Call on Even Parity(P=1)
CPO 16-bit address Call on Odd Parity(P=0)
Conditional Return Instructions
RC Return on Carry
RNC Return on No Carry
RZ Return on Zero
RNZ Return on No Zero
RM Return on Minus
RP Return on Plus
RPE Return on Even Parity
RPO Return on Odd Parity



Stack Operation and Sub Routine [In 8085 Microprocessor] Stack Operation and Sub Routine [In 8085 Microprocessor] Reviewed by Sandesh Shrestha on 13 March Rating: 5

No comments:

Powered by Blogger.