Problem – Write an assembly language program in 8085 microprocessor to find maximum and minimum of 10 numbers.
Minimum: 01H, Maximum: FFH
In CMP instruction:
If Accumulator > Register then carry and zero flags are reset
If Accumulator = Register then zero flag is set
If Accumulator < Register then carry flag is set
Assumption – List of numbers from 2050H to 2059H and output at 2060H and 2061H.
- Maximum number is stored in B register and minimum in C register
- Load counter in D register
- Load starting element in Accumulator, B and C register
- Compare Accumulator and B register
- If carry flag is not set then transfer contents of Accumulator to B. Else, compare Accumulator with C register, if carry flag is set transfer contents of Accumulator to C
- Decrement D register
- If D>0 take next element in Accumulator and go to point 4
- If D=0, store B and C register in memory
- End of program
|2000H||LXI H, 2050H||Load starting address of list|
|2003H||MOV B, M||Store maximum|
|2004H||MOV C, M||Store minimum|
|2005H||MVI D, 0AH||Counter for 10 elements|
|2007H||LOOP||MOV A, M||Retrieve list element in Accumulator|
|2008H||CMP B||Compare element with maximum number|
|2009H||JC MIN||Jump to MIN if not maximum|
|200CH||MOV B, A||Transfer contents of A to B as A > B|
|200DH||MIN||CMP C||Compare element with minimum number|
|200EH||JNC SKIP||Jump to SKIP if not minimum|
|2011H||MOV C, A||Transfer contents of A to C if A < minimum|
|2012H||SKIP||INX H||Increment memory|
|2013H||DCR D||Decrement counter|
|2014H||JNZ LOOP||Jump to LOOP if D > 0|
|2017H||LXI H, 2060H||Load address to store maximum|
|201AH||MOV M, B||Move maximum to 2060H|
|201BH||INX H||Increment memory|
|201CH||MOV M, C||Move minimum to 2061H|
- One by one all elements are compared with B and C register.
- Element is compared with maximum, if it greater than maximum then it is stored in B register. Else, it is compared with minimum and if it is less than minimum then it stored in C regiter.
- Loop executes 10 number of times.
- At the end of 10 iterations, maximum and minimum are stored at 2060H and 2061H respectively.
- 8085 program to find maximum of two 8 bit numbers
- 8085 program to find minimum value of digit in the 8 bit number
- 8085 program to find larger of two 8 bit numbers
- 8085 program to find the sum of series of even numbers
- 8085 program to find the sum of first n natural numbers
- 8085 program to find smallest number between two numbers
- 8085 program to count total even numbers in series of 10 numbers
- 8085 program to count total odd numbers in series of 10 numbers
- 8085 program to add two 8 bit numbers
- 8085 program to add two 16 bit numbers
- 8085 program to add 2-BCD numbers
- 8085 program to divide two 8 bit numbers
- 8085 program to divide two 16 bit numbers
- 8085 program to sum of two 8 bit numbers without carry
- 8085 program to multiply two 8 bit numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.