DIGITAL ELECTRONICS AND
MICROPROCESSORS
Passing parameters to
subroutines
By Ashok Ranade
Techniques
Exercise 1
Write the main program which passes two numbers stored in B and C
registers to a subroutine which returns the sum of these numbers in D
register and the difference (B-C) in E
Assume that the sum does not exceed a byte and the number in B is
greater than that in C
Program and results
Exercise 2
Write the main program to write two numbers in memory locations 3000H
and 3001H. Then call a subroutine which will calculate the sum and
difference of these numbers and store the result in the locations 4000H and
4001H
LDA - Is for loading the accumulator. i.e) It is used to load the accumulator from
the memory. (Data moves/will be copied from memory to accumulator ).
STA - Is for storing the accumulator value to the memory location((Data moves/will
be copied from accumulator to the memory )
Example 2
Example 3
The main program loads the pointers to memory address 3000H and
4000H. It also loads number of bytes in E register
Subroutine transfers the data from the memory location indicated by the first
pointer to the memory location starting from the address indicated by the
second pointer.
The STAX B instruction in the 8085 microprocessorcopies the contents of the
accumulator into a memory location specified by the contents of the register
pair
The INX B instruction in the 8085 microprocessor increases the BC register
pair by one
Program
Stack
Stack is a part of RAM (Random Access Memory)
It is used as Last – IN-First-Out (LIFO) memory
To make use of stack first Stack pointer is initialized
Usually it is initialized to FFFF
Stack is used in two ways
User – PUSH and POP instructions
System --- When a subroutine is called.
Program
Interrupt Service Routine
Interrupt
Interrupt Service Routine Ends
RET
PUSH and POP instructions
The LXI SP instruction in an 8085
microprocessor loads a 16-bit address into the
stack pointer (SP) register pair:
Program
After PUSH D, SP is decremented by
1 so it becomes 24FF. At this location
03H is stored. Then again it is
decremented by 1 so it becomes
24EF. At this location 45H is stored
Demo for POP operation
When POP D is executed the contents from
the stack are read and loaded into E. Then
stack pointer is incremented and the contents
are read into the register D
And again the stack pointer is incremented