---
title: "8086 ALP: largest and smallest, display"
subject: "Microprocessor"
chapter: 3
key: "semester_4/microprocessor:alp-8086-largest-smallest-display"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-largest-smallest-display
site: BCT Engineering
---

# 8086 ALP: largest and smallest, display

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2073 Bhadra, 8 marks
- Video: [Execution of the 8086 Assembly Language Programming code To find the Largest and Smallest number.](https://www.youtube.com/watch?v=oP0tyaJQeyU) — Vaibhav KKM
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-largest-smallest-display
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write an assembly language program for 8086 to find the largest and smallest numbers of an array having 10 numbers. Display the found numbers in the clear screen.

## Short answer

For array of 10 bytes, initialize largest in BL and smallest in BH with first element, compare remaining nine using unsigned JBE/JAE, update. Clear screen, display both in decimal. For sample array largest=120, smallest=3.

## Answer

**Method:** the first element is taken as both the largest (BL) and the smallest (BH); the remaining nine are compared one by one and BL/BH are updated (unsigned comparison). The screen is cleared and both values are displayed in decimal with the helper `PRINT_DEC`.

```asm
.MODEL SMALL
.STACK 100H

DISPSTR MACRO MSG            ; display a '$'-terminated string
        LEA  DX,MSG
        MOV  AH,09H
        INT  21H
        ENDM

CLRSCR  MACRO                ; clear screen and home the cursor
        MOV  AX,0600H        ; scroll whole window (AL=0 -> blank it)
        MOV  BH,07H          ; normal attribute
        MOV  CX,0000H        ; upper-left corner (row 0, col 0)
        MOV  DX,184FH        ; lower-right corner (row 24, col 79)
        INT  10H
        MOV  AH,02H          ; set cursor position
        MOV  BH,00H          ; page 0
        MOV  DX,0000H        ; row 0, col 0
        INT  10H
        ENDM

.DATA
    ARR   DB 25,7,98,64,3,120,45,88,17,60
    MSG1  DB 'Largest  = $'
    MSG2  DB 'Smallest = $'
    CRLF  DB 13,10,'$'

.CODE
MAIN PROC
    MOV  AX,@DATA
    MOV  DS,AX

    LEA  SI,ARR            ; SI -> array
    MOV  BL,[SI]           ; BL = largest (first element)
    MOV  BH,BL             ; BH = smallest
    INC  SI
    MOV  CX,9              ; 9 more elements
NEXT:
    MOV  AL,[SI]
    CMP  AL,BL
    JBE  NOTMAX            ; AL <= largest
    MOV  BL,AL             ; new largest
NOTMAX:
    CMP  AL,BH
    JAE  NOTMIN            ; AL >= smallest
    MOV  BH,AL             ; new smallest
NOTMIN:
    INC  SI
    LOOP NEXT

    PUSH BX                ; CLRSCR uses BH, so keep largest/smallest safe
    CLRSCR                 ; clear screen
    POP  BX
    DISPSTR MSG1
    MOV  AL,BL
    XOR  AH,AH
    CALL PRINT_DEC         ; show largest
    DISPSTR CRLF
    DISPSTR MSG2
    MOV  AL,BH
    XOR  AH,AH
    CALL PRINT_DEC         ; show smallest
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

; ---- print the unsigned number in AX in decimal (registers preserved)
PRINT_DEC PROC
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX
    MOV  BX,10
    XOR  CX,CX             ; digit counter
PD1:XOR  DX,DX
    DIV  BX                ; AX = quotient, DX = remainder (digit)
    PUSH DX
    INC  CX
    OR   AX,AX
    JNZ  PD1
PD2:POP  DX                ; digits come out in correct order
    ADD  DL,30H            ; to ASCII
    MOV  AH,02H
    INT  21H
    LOOP PD2
    POP  DX
    POP  CX
    POP  BX
    POP  AX
    RET
PRINT_DEC ENDP

END MAIN
```

**Output:** `Largest  = 120` and `Smallest = 3`. (For signed numbers use JLE/JGE instead of JBE/JAE.)

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How are the largest and smallest values initialised?
   A. Both to 0
   B. BL = 0 and BH = 0FFH
   C. Both to the first array element
   D. Largest to the last element, smallest to the first
   Answer: C. The first element is taken as both largest (BL) and smallest (BH), and the remaining nine are compared. (Key point: Initialisation)

2. Why is CX set to 9 for a 10-element array?
   A. The first element is already loaded, so nine remain to compare
   B. One element is reserved for the result
   C. The array index starts at 9
   D. LOOP always runs one extra time
   Answer: A. After loading element 1 and incrementing SI, only 9 elements are left. (Key point: Loop count)

3. Which jumps are used for the unsigned comparison, and what changes for signed numbers?
   A. JBE/JAE; use JLE/JGE for signed
   B. JLE/JGE; use JBE/JAE for signed
   C. JE/JNE; use JZ/JNZ for signed
   D. JBE/JAE for both signed and unsigned
   Answer: A. JBE/JAE test the carry flag for unsigned data; JLE/JGE test sign and overflow for signed data. (Key point: Comparison type)

4. Why is BX pushed before CLRSCR?
   A. CLRSCR uses BH, which would destroy the smallest value
   B. CLRSCR uses BL only
   C. The stack must be cleared first
   D. INT 10h needs BX on the stack
   Answer: A. The CLRSCR macro loads BH with the attribute and later page number, overwriting the saved smallest value. (Key point: Register preservation)

## Related in Microprocessor

- [8086 ALP: count vowels and display string](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-count-vowels-display) — Microprocessor, chapter 3
- [8086 ALP: sum of 100 even numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-sum-even-numbers) — Microprocessor, chapter 3
- [8086 ALP: alternate case display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alternate-case) — Microprocessor, chapter 3
- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
- [8086 ALP: display only alphabetic characters](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alphabetic-only) — Microprocessor, chapter 3
- [8086 ALP: words on lines and word count](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-words-lines-count) — Microprocessor, chapter 3

## Related in other subjects

- [Pass 2D array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-2d-array-largest-smallest) — Computer Programming, chapter 7
- [Pass array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-largest-smallest) — Computer Programming, chapter 7
- [Largest of n numbers in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-largest-n-numbers) — Computer Programming, chapter 11
- [Function returning largest of array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Alargest-from-array-function) — Computer Programming, chapter 7
