In the article, Microprocessor 8085 program to find the smallest number from an array of data in assembly language programming (ALP) is explained.
It is highly recommended to learn the instruction set of 8085 in detail before programming.
Problem:
Find the smallest number in a block of data. The length of the block is in memory location 2200H and the block itself starts from memory location 2201H.
Store the smallest number in memory location 2300H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.
Algorithm:
- Load the address of the first element of the array in HL pair
- Move the count to B – register.
- Increment the pointer.
- Get the first data in Accumulator.
- Decrement the count.
- Increment the pointer.
- Compare the content of memory addressed by HL pair with that of Accumulator.
- If carry = 1, go to step 10 or if Carry = 0 go to step 9.
- Move the content of memory addressed by HL to Accumulator.
- Decrement the count.
- Check for Zero of the If ZF = 0, go to step 6, or if ZF = 1 go to next step.
- Store the smallest data in memory.
- Terminate the program.
Program:
LXI H,2200H ; Initialize the memory pointer
MOV B, M ; Copy contents of memory to register B
INX H ; Set pointer for array Load the Count
MOV A, M ; Set 1st element as smallest number
DCR B ; Decrement the count
LOOP:INX H ; Get the next number
CMP M ; If A- reg < M go to AHEAD
JC AHEAD ; Jump to ahead if Carry=1
MOV A, M ; Set the new value as smallest
AHEAD: DCR B ; Decrement the counter
JNZ LOOP ; Repeat comparisons till count = 0
STA 2300H ; Store the largest value at 2300
HLT ; Terminate the program
Sample Example:
Input:
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) = 56H
Result = (2300H) = 34H
Recent posts
Related posts:
- Terminology Used in Microprocessor and Microcontroller
- CISC and RISC Processor Architecture
- Von Neumann and Harvard Architecture
- Basics of Microprocessor and Microcontroller
- Introduction to Microprocessor 8085
- Architecture of 8085 Microprocessor
- Pin Diagram of 8085 Microprocessor and Pin Description
- Addressing Modes in 8085 Microprocessor
- Data Transfer Instructions in 8085 Microprocessor
- Arithmetic Instructions in 8085 Microprocessor
- Logical Instructions in 8085 Microprocessor
- Branching instructions in 8085 Microprocessor
- Machine Control Instructions in 8085 Microprocessor
- Timing Diagram of 8085 Instructions
- Stack and Subroutine in 8085 Microprocessor
- Interrupts in 8085 Microprocessor
- Assembler Directives of 8085 Microprocessor
- Simple Data Transfer Program in 8085 Microprocessor
- Microprocessor 8085 Addition and Subtraction Programs
- Programs on Logical Instructions in 8085 Microprocessor
- Multiplication Programs in 8085 Microprocessor
- Division Programs in 8085 Microprocessor
- Introduction to Assembly Language Programming
- 8085 Program to Find the Largest Number in an Array of Data
- 8085 Program to Count Negative Numbers | ALP to Count Negative Numbers
- 8085 Program to Arrange an Array of Data in Ascending Order
- 8085 Program to Arrange an Array of Data in Descending Order
- 8085 Program to Find the Square of a Number from 0 to 9 Using a Table of Square