19EAC285 Micro-Controller Lab
Lab sheet 5: 8085 Branching and Stack Operations
Subject: Microcontroller Lab Register Number:
Sub Code: 19EAC285 Name:
Experiment No. : 5 Date:
Course Outcome: CO3
Branching Operations:
1. Write an assembly language program to find the largest and the smallest number in an
array. The algorithm for finding the largest number is given below:
1. Fetch the first element from the memory location and load it in the accumulator.
2. Initialize a counter (register) with the total number of elements in an array.
3. Decrement the counter by 1.
4. Compare the accumulator content with the next element
5. If the accumulator content is smaller, then move the largest element to the accumulator. Else
continue.
6. Decrement the counter by 1.
7. Repeat steps 5 to 8 until the counter reaches zero
8. Store the result (accumulator content) in the specified memory location
Output:
1
19EAC285 Micro-Controller Lab
2. Write an assembly language program using loops to add the numbers starting from 1 to 50.
B=1+2+3+. ......... +49+50
Logic:
Output:
2
19EAC285 Micro-Controller Lab
Stack Operations
The stack is a reserved area of the memory in RAM where we can store temporary information. The data
is being stored into the stack in a last-in-first-out manner. PUSH – This is the instruction we use to write
information on the stack. POP – This is the instruction we use to read information from the stack. The
8085 has a 16-bit register known as the Stack Pointer (SP). The function of the stack pointer is to hold
thestarting address of the stack. Storing data from Register pairs such as BC, HL, and DE is specified by
PUSH B, PUSH H, and PUSH D respectively. POP instruction is also used in the same way.
Example:
LXI SP, 8200H # Load the stack pointer register with a 16-bit address.
LXI B, 1650H # Load the register pair with a 16-bit data
MVI D, 05H #initializes the delay counter
PUSH B # Copies the contents of the specified register pair on the stack
DELAY1: DCR D #Start delay loop
JNZ DELAY1
POP H # Copies the contents of the top two memory locations of the stack into HL Pair
HLT
Run the above program and note down how the Value of the SP before and after the PUSH and POP
operations. Take screenshots of the changes in the values of registers and stack memory. Also
diagrammatically show how the values from the BC register pair are copied to the HL register pair.
3
19EAC285 Micro-Controller Lab
Output:
Evaluation:
Criteria Marks Comments
Preparedness
Performance
Viva
Output/Completion
Signature of Faculty: Date:
4
19EAC285 Micro-Controller Lab
5
19EAC285 Micro-Controller Lab