Write and execute an alp to 8086 Microprocessor to pick the median from the given array of numbers.

Aim:

To write and execute an Assembly language Program (ALP) to 8086 processor to pick the median from the given array of numbers.

Tools:

PC installed with TASM.

Program:

.MODEL SMALL
.STACK 45H
ASSUME CS : CODE, DS : DATA
DATA SEGMENT
ARRY DW 0125H, 0144H, 3001H, 0003H, 0002H
MEDIAN DW  ?
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
START :  MOV AX, DATA
MOV DS, AX
MOV DX, COUNT - 1
BACK: MOV CX, DX
MOV SI, OFFSET ARRY
AGAIN: MOV AX, [SI]
CMP AX, [SI + 2]
JC GO
XCHG AX, [SI + 2]
XCHG AX, [SI]
GO: INC SI
INC SI
LOOP AGAIN
DEC DX
JNZ BACK
MOV SI, OFFSET ARRY
MOV AX, [SI + 4]
MOV MEDIAN, AX
INT 03H
CODE ENDS
END START
END

Result:

Input:

0125H, 0144H, 3001H, 0003H, 0002H

Output:

Median = 3001H

Viva-voce questions:

1. What is meant by median of an array?
2. what do you mean by addressing mode?
3. What is the addressing mode of an instruction communicated to the cpu?
4. What are the assembler directives?
5. Depending on what value, Loop repeats for no. of times?