Skip to content
Related Articles

Related Articles

8085 program to find maximum and minimum of 10 numbers
  • Last Updated : 22 May, 2018

Problem – Write an assembly language program in 8085 microprocessor to find maximum and minimum of 10 numbers.

Example –

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.

Algorithm –

  1. Maximum number is stored in B register and minimum in C register
  2. Load counter in D register
  3. Load starting element in Accumulator, B and C register
  4. Compare Accumulator and B register
  5. 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
  6. Decrement D register
  7. If D>0 take next element in Accumulator and go to point 4
  8. If D=0, store B and C register in memory
  9. End of program


2000HLXI H, 2050HLoad starting address of list
2003HMOV B, MStore maximum
2004HMOV C, MStore minimum
2005HMVI D, 0AHCounter for 10 elements
2007HLOOPMOV A, MRetrieve list element in Accumulator
2008HCMP BCompare element with maximum number
2009HJC MINJump to MIN if not maximum
200CHMOV B, ATransfer contents of A to B as A > B
200DHMINCMP CCompare element with minimum number
200EHJNC SKIPJump to SKIP if not minimum
2011HMOV C, ATransfer contents of A to C if A < minimum
2012HSKIPINX HIncrement memory
2013HDCR DDecrement counter
2014HJNZ LOOPJump to LOOP if D > 0
2017HLXI H, 2060HLoad address to store maximum
201AHMOV M, BMove maximum to 2060H
201BHINX HIncrement memory
201CHMOV M, CMove minimum to 2061H

Explanation –

  1. One by one all elements are compared with B and C register.
  2. 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.
  3. Loop executes 10 number of times.
  4. At the end of 10 iterations, maximum and minimum are stored at 2060H and 2061H respectively.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :