Write a program to find out the largest number from a given unordered array and save them in variables named LRGST.

0 votes
asked by about Emu8086 Microprocessor Emulator

1 Answer

0 votes
answered by (101k points)

Here is a sample program in assembly language for the Emu8086 Microprocessor Emulator that finds the largest number from an array and saves it in a variable named LRGST:

ORG 100h

DATA SEGMENT
ARR DB 5, 3, 9, 2, 6   ; example array of numbers
LRGST DB ?           ; variable to hold the largest number
DATA ENDS

CODE SEGMENT
START:
MOV AX, @DATA      ; initialize data segment
MOV DS, AX

MOV BL, ARR       ; load the first number in array into BL
MOV BH, ARR+1     ; load the second number in array into BH

COMPARE:
CMP BL, BH        ; compare the two numbers in BL and BH
JGE UPDATE       ; jump to UPDATE if BL is greater than or equal to BH
MOV BL, BH       ; otherwise, move BH to BL 
INC BH           ; increment index to move to next number in array
CMP BH, 5        ; compare index to array length (assuming length is 5)
JG DISPLAY      ; if index is greater than array length, display largest number
JMP COMPARE    ; otherwise, compare the next two numbers

UPDATE:
MOV BH, ARR+1   ; move the next number in array to BH
INC BH          ; increment index to move to next number in array 
CMP BH, 5       ; compare index to array length (assuming length is 5)
JG DISPLAY     ; if index is greater than array length, display largest number
JMP COMPARE   ; otherwise, continue comparing numbers in array 

DISPLAY:
MOV LRGST, BL   ; move largest number (in BL) to LRGST variable
INT 3H           ; exit program
CODE ENDS
END START

You can modify the "ARR DB" line to include any array of numbers and the program will find the largest number. After the program is run, the largest number will be stored in the LRGST variable.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...