In: Computer Science
using Windows 32 bit framework , Write an assembly language
program to find the second minimum
element (formally, second minimum is larger than the minimum but
smaller than all
the other elements in the array) of an array of size 100.
Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95
dup(?) and
show that your program works for the first five elements. Display
the second minimum in a message box using Input output macro
;given doubleword array and find first small number array and after second Small.
.MODEL FLAT
.STACK 256
.DATA
nbrArray DWORD 23,45,21,67,78,95 DUP ?
SMALLEST DWORD ?
SECOND_SMALLEST DWORD ?
.CODE
MAIN PROC
MOV EAX,0
LEA EBX nbrArray ;get address of nbrArray
MOV SMALLEST,EBX ; mov data in ebx to smallest
COMPARE_1:
INC EAX ;increment next value in array that stored eax
CMP EAX,10 ;compare value in eax with 10
JE UPDATED_SMALLEST ;if equal then jump Updated_smallest
LEA EBX,nbrArray ;get address of nbrArray
CMP EBX,SMALLEST ;compare value in Smllest with ebx value
JL UPDATE_SMALLEST ;if lessthan then jump update_smallest
JMP COMPARE_1 ; jump to compare_1
UPDATE_SMALLEST:
MOV SMALLEST, EBX ; load ebx to smallest
JMP COMPARE_1 ; jump compare_1
UPDATED_SMALLEST:
MOV EAX,0 ;return 0
FIND_SECOND_SMALLEST:
LEA EBX, nbrArray ;get address of nbrArray
CMP EBX, SMALLEST ;compare ebx with smallest
JE SPECIAL_CASE ;if equal jump to special case
MOV SECOND_SMALLEST,EBX ;load ebx to Second_smallest
JMP COMPARE_2 ;jump
SPECIAL_CASE:
INC EAX ;increment
JMP FIND_SECOND_SMALLEST ; jump to find_second_smallest
COMPARE_2:
INC EAX
CMP EAX, 10
JE EXIT
LEA EBX, nbrArray ;get address of nbrArray
CMP EBX, SECOND_SMALLEST ;compare
JL UPDATE_SECOND_SMALLEST ;if less then jump to
update_second_smallest
JMP COMPARE_2 ; jump to
UPDATE_SECOND_SMALLEST:
CMP EBX,SMALLEST ; compare ebx that with 1st smallest
JE COMPARE_2 ; if equal then go to compare_2
MOV SECOND_SMALLEST,EBX ;load ebx that stored second smallest to
Second_smallest
JMP COMPARE_2 ; jump to
MAIN ENDP
END MAIN