Write an 8086 assembly language program that finds the largest, and the second largest number from a list of 10 numbers stored in the memory 6m Jun2006

By | January 29, 2015

Write an 8086 assembly language program that finds the largest, and the second largest number from a list of 10 numbers stored in the memory 6m Jun2006

To understand program for Largest in an array in detail Please Click this link below http://cssimplified.com/computer-organisation-and-assembly-language-programming/an-assembly-program-for-finding-the-largest-number-in-array-of-10-elements

DATA SEGMENT
ARR DB 5,3,7,1,9,2,6,8,4
LEN DW $-ARR
LARGE DB ?
SECOND DB ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA SI,ARR
MOV AL,ARR[SI]
MOV LARGE,AL

MOV CX,LEN
REPEAT1:
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE

MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT1

LEA SI,ARR
MOV AL,ARR[SI]
MOV SECOND,AL

MOV CX,LEN
REPEAT2:
MOV AL,ARR[SI]
CMP SECOND,AL
JG SKIP

CMP LARGE,AL
JLE SKIP

MOV SECOND,AL
SKIP:
INC SI
LOOP REPEAT2

MOV AH,4CH
INT 21H
CODE ENDS
END START

Program code: -

 

 DATA SEGMENT
 
ARR DB 5,3,7,1,9,2,6,8,4
LEN DW $-ARR
LARGE DB ? 
SECOND DB ?
DATA ENDS
 
CODE SEGMENT 
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
 
LEA SI,ARR
MOV AL,ARR[SI]
MOV LARGE,AL
 
MOV CX,LEN
REPEAT1: 
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE
 
MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT1 
 
LEA SI,ARR
MOV AL,ARR[SI]
MOV SECOND,AL
 
MOV CX,LEN
REPEAT2: 
MOV AL,ARR[SI]
CMP SECOND,AL
JG SKIP
 
CMP LARGE,AL
JLE SKIP
 
MOV SECOND,AL
SKIP:
INC SI
LOOP REPEAT2 
 
MOV AH,4CH
INT 21H 
CODE ENDS
END START

 

Screen shots: -

Asm_program_Second_Largest_in_Array

Before Execution: -

Asm_program_Second_Largest_in_Array_OP1

After Execution: -

Asm_program_Second_Largest_in_Array_OP2