- 2070 Magh · 8 marks
8086 ALP: max and min of 16-bit list
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.
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.
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.
.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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- 8086 ALP: largest and smallest, display · Microprocessor, chapter 3
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- 8085 ALP: square of ten numbers · Microprocessor, chapter 2
- 8086 ALP: sum of 100 even numbers · Microprocessor, chapter 3
- 8085 ALP: transfer data with more than 3 ones · Microprocessor, chapter 2
- 8086 ALP: alternate case display · Microprocessor, chapter 3
- Greatest and smallest of ten numbers · Computer Programming, chapter 11
- Pass array; largest and smallest · Computer Programming, chapter 7
- Pass 2D array; largest and smallest · Computer Programming, chapter 7
- Algorithm for largest and smallest · Computer Programming, chapter 2