Median of Elements of An Array of 8-Bit Numbers, 8086 Assembly Language Program, .Asm File Can Be Executed by Using MASM or TASM

You might also like

Download as ehtml, pdf, or txt
Download as ehtml, pdf, or txt
You are on page 1of 3

;This is 8086 assembly language program to find the median of the ;given elements of data (8-bit hexadecimal numbers)

; We need to first arrange the elements in their ascending order. ;Median of n elements where n is odd =middle term of data arranged ;in ascending order ; Median of n elements where n is even =[(n/2)the term +((n1)/2)th term]/2

assume cs:code, ds:data data segment ; the program contains array consisting of even and odd number ; of elements, taken one at a time ; Execute odd array at one time and remove comment for even array at ;second time and check for both the cases ;This is odd array array db 10h, 3ah, 9bh, 57h, 83h, 77h, 0f5h,42h, 0c9h ;This is even array ;array db 15h,7ah,0cch,0adh,59h,4bh,82h,9ch,30h,2eh count db $-array median db ? data ends code segment start: mov ax, data mov ds, ax mov ax, 0000h mov bx, 0000h mov cx, 0000h mov dx, 0000h

; arrange the numbers in ascending orders mov bl, count mov cl, count sub cl, 01h mov dl, cl loop1: mov cl, dl mov si, offset array loop2: mov al, [si] cmp al, [si+1] jb loop3 xchg al, [si+1] xchg al, [si] loop3: inc si dec cl jnz loop2 dec dl jnz loop1 ; find the number of elements are even or odd mov al, bl mov bl, 02h div bl mov dl, al mov si, dx cmp ah, 00h je even1 jmp odd1 odd1: mov al, [si] jmp med even1: mov al, [si] dec si mov cl, [si] add al, cl div bl med: mov median, al mov ah, 4ch int 21h code ends

end start

You might also like