Write an 8086 assembly language program that finds the smallest and the second smallest number from a list of 10 numbers stored in memory. 7m Jun2008

By | August 11, 2015

Write an 8086 assembly language program that finds the smallest and the second smallest number from a list of 10 numbers stored in memory. 7m Jun2008

To understand program for Largest or Smallest 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
SMALL 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 SMALL,AL

MOV CX,LEN
REPEAT1:
MOV AL,ARR[SI]
CMP SMALL,AL
JL NOCHANGE

MOV SMALL,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
JL SKIP

CMP SMALL,AL
JGE 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
SMALL 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 SMALL,AL
MOV CX,LEN
REPEAT1:
MOV AL,ARR[SI]
CMP SMALL,AL
JL NOCHANGE
MOV SMALL,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
JL SKIP
CMP SMALL,AL
JGE SKIP
MOV SECOND,AL
SKIP:
INC SI
LOOP REPEAT2
MOV AH,4CH
INT 21H
CODE ENDS
END START

Screen shots: -

Asm_program_Second_Smallest_in_Array

Before Execution: -

Asm_program_Second_Smallest_in_Array_OP1

After Execution: -

Asm_program_Second_Smallest_in_Array_OP2

 

 

2(a) Explain the process of handling an interrupt that occurs during program execution, with the help of an example. 9

Solved program can be found on this link http://cssimplified.com/computer-organisation-and-assembly-language-programming/explain-the-process-of-handling-an-interrupt-that-occurs-during-a-program-9m-jun2006