May 13, 2009

Assembly code for finding maximum and minimum number from an array and placing them in different arrays

Here is the assembly code for sorting maximum number and minimum number from an array. The code is written and tested in emu8086 software.

Sorting even and odd number and placing them in different arrays:

CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 100H
MOV CX,4H

TOP:

MOV AX,00H
MOV BX,00H
MOV BL,COUNT
MOV BH,00H
MOV AL,DATA[BX]
MOV DL,DATA[BX]
MOV STORE,DL
MOV AH,00H
MOV BL,02H
MOV BH,0H
DIV BL

JCXZ EXIT:

CMP AH,00H
JE EVEN:
JNE ODD:

EVEN:
MOV DH,0H
LEA SI,STORE_EVEN
ADD SI,COUNT_EVEN
MOV [SI],DL
INC COUNT_EVEN
JMP EXIT:

ODD:
MOV DH,00H
LEA SI,STORE_EVEN
ADD SI,COUNT_ODD
ADD SI,100H
MOV [SI],DL
INC COUNT_ODD
JMP EXIT:

EXIT:
INC COUNT
LOOP TOP:


HLT

;ORG 200H
;first semicolon should be omitted if the code is fed in MDA-8086 or MTS-86c
DATA DB 23H,34H,62H,65H
STORE DB ?
STORE_EVEN DB ?
STORE_ODD DB ?
COUNT DB 0H
COUNT_EVEN DW 0H
COUNT_ODD DW 0H


CODE ENDS
END

No comments:

Post a Comment

feel free to comment, I will be as responsive as possible. just don't spam.