---
title: "8086 ALP: max and min of 16-bit list"
subject: "Microprocessor"
chapter: 3
key: "semester_4/microprocessor:alp-8086-max-min-16bit"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-max-min-16bit
site: BCT Engineering
---

# 8086 ALP: max and min of 16-bit list

Microprocessor · Chapter 3: Programming with 8086 Microprocessor

- Asked in: 2070 Magh, 8 marks
- Video: [Assembly Language Programs of 8086- Multiplication, Division, Biggest, Smallest](https://www.youtube.com/watch?v=fcCswkm1R_Q) —  Deepak Verma
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8086-max-min-16bit
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-3

## Question

Write a program for 8086 to find the largest and smallest value from a list of ten 16 bit data and store the result in maxval and minval variables.

## Short answer

For ten 16-bit words, initialize AX max and BX min with first word, compare remaining nine unsigned, increment SI by 2, store in MAXVAL and MINVAL. Sample result MAXVAL=0A5A5H, MINVAL=0010H.

## Answer

**Method:** load the first word into AX (maximum) and BX (minimum), then compare the other nine words (unsigned) with them, updating AX and BX. Finally store them in `MAXVAL` and `MINVAL`. Words occupy 2 bytes, so SI is incremented by 2.

```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
    NUMS   DW 1234H, 0056H, 8000H, 0FFFH, 4321H
           DW 0A5A5H, 0010H, 7FFFH, 2222H, 9000H
    MAXVAL DW ?
    MINVAL DW ?

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

    LEA  SI,NUMS           ; SI -> list of ten words
    MOV  AX,[SI]           ; AX = maximum so far
    MOV  BX,AX             ; BX = minimum so far
    ADD  SI,2
    MOV  CX,9              ; nine remaining words
NEXT:
    MOV  DX,[SI]           ; DX = next word
    CMP  DX,AX
    JBE  CHKMIN            ; DX <= max
    MOV  AX,DX             ; new maximum
CHKMIN:
    CMP  DX,BX
    JAE  SKIP              ; DX >= min
    MOV  BX,DX             ; new minimum
SKIP:
    ADD  SI,2              ; next word
    LOOP NEXT
    MOV  MAXVAL,AX         ; store results
    MOV  MINVAL,BX
    MOV  AH,4CH            ; return to DOS
    INT  21H
MAIN ENDP

END MAIN
```

**Result:** MAXVAL = 0A5A5H and MINVAL = 0010H for the sample list. For signed 16-bit data, replace JBE with JLE and JAE with JGE.

## Check yourself

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

1. Why does SI increase by 2 after each comparison?
   A. Each word occupies 2 bytes
   B. LOOP adds 2 automatically
   C. The array has 2 columns
   D. CMP uses two bytes of the next element
   Answer: A. The data are 16-bit words, so consecutive elements are 2 bytes apart. (Key point: Pointer step)

2. Which registers hold the running maximum and minimum?
   A. AX = minimum, BX = maximum
   B. AX = maximum, BX = minimum
   C. CX = maximum, DX = minimum
   D. Both are kept only in memory
   Answer: B. AX is loaded with the first word as maximum and BX with the same value as minimum. (Key point: Registers used)

3. What are MAXVAL and MINVAL for the sample list (unsigned)?
   A. MAXVAL = 9000H, MINVAL = 0010H
   B. MAXVAL = 7FFFH, MINVAL = 0010H
   C. MAXVAL = 0A5A5H, MINVAL = 0056H
   D. MAXVAL = 0A5A5H, MINVAL = 0010H
   Answer: D. Unsigned, 0A5A5H is the largest and 0010H the smallest of the ten words. (Key point: Result for sample)

4. How must the program change for signed 16-bit data?
   A. Use ADD SI,4
   B. Replace JBE with JLE and JAE with JGE
   C. Replace CMP with TEST
   D. Use byte registers instead
   Answer: B. Signed comparison needs the signed jumps JLE/JGE; JBE/JAE treat 8000H as a large positive number. (Key point: Signed data)

## Related in Microprocessor

- [8086 ALP: largest and smallest, display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-largest-smallest-display) — Microprocessor, chapter 3
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [8085 ALP: square of ten numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-square-numbers) — Microprocessor, chapter 2
- [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
- [8085 ALP: transfer data with more than 3 ones](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-greater-than-3) — Microprocessor, chapter 2
- [8086 ALP: alternate case display](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8086-alternate-case) — Microprocessor, chapter 3

## Related in other subjects

- [Greatest and smallest of ten numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-greatest-smallest-ten) — Computer Programming, chapter 11
- [Pass array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-largest-smallest) — Computer Programming, chapter 7
- [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
- [Algorithm for largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-algorithm-largest-smallest) — Computer Programming, chapter 2
