Created
July 8, 2022 11:53
-
-
Save prathamesh-mutkure/dfa049afa1277fd83cb0a4c287a90107 to your computer and use it in GitHub Desktop.
Assembly Language Program for Array Manipulations (8086)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;--------------------------------------------------------------------------- | |
;---------------------------- START OF PROGRAM ----------------------------- | |
;--------------------------------------------------------------------------- | |
INCLUDE 'EMU8086.INC' | |
.MODEL SMALL | |
.STACK 100h | |
.DATA | |
arr DB 10 dup(0) | |
even_arr DB 10 dup(0) | |
odd_arr DB 10 dup(0) | |
count DB 10 | |
even_count DB 0 | |
odd_count DB 0 | |
even_large DB 0 | |
odd_large DB 0 | |
even_small DB 0 | |
odd_small DB 0 | |
rem DB 0 | |
.CODE | |
;--------------------------------------------------------------------------- | |
;---------------------------- TAKE ARRAY INPUT ----------------------------- | |
;--------------------------------------------------------------------------- | |
takeUserInput PROC | |
MOV SI, OFFSET arr | |
MOV BH, count | |
MOV DL, 10h | |
MOV BL, 0h | |
PRINTN "" | |
PRINT "Enter ten 8-bit two digit Numbers: " | |
up: | |
scanNum: | |
mov ah, 01h | |
int 21h | |
cmp al, 32 ; Check if user pressed SPACE KEY | |
je exit | |
mov ah, 0 | |
sub al, 48 ; ASCII to DECIMAL | |
mov cl, al | |
mov al, bl ; Store the previous value in AL | |
mul dl ; multiply the previous value with 10 | |
add al, cl ; previous value + new value ( after previous value is multiplyed with 10 ) | |
mov bl, al | |
jmp scanNum | |
exit: | |
MOV [SI], BL | |
INC SI | |
DEC BH | |
JNZ up | |
RET | |
takeUserInput ENDP | |
;--------------------------------------------------------------------------- | |
;---------------------------- PRINT ARRAY ---------------------------------- | |
;--------------------------------------------------------------------------- | |
printArray MACRO array cnt | |
LOCAL up | |
MOV SI, OFFSET array | |
MOV CL, cnt | |
up: | |
MOV AH, 00 ; Spliting the number into 2 | |
MOV AL, [SI] | |
MOV BL, 10h | |
DIV BL | |
MOV rem, AH | |
MOV DL, AL | |
ADD DL, 48 | |
MOV AH, 02h | |
INT 21h ; Printing value at one's place | |
MOV DL, rem | |
ADD DL, 48 | |
MOV AH, 02h | |
INT 21h ; Printing value at ten's place | |
MOV DL, 32 ; Print Space | |
INT 21h | |
INC SI | |
DEC CL | |
JNZ up ; Moving to next number | |
printArray ENDM | |
;--------------------------------------------------------------------------- | |
;---------------------------- SORT ARRAY ----------------------------------- | |
;--------------------------------------------------------------------------- | |
sortArray PROC | |
MOV CL, count | |
SUB CL, 01h | |
outer_loop: | |
MOV SI, OFFSET arr | |
MOV CH, CL | |
inner_loop: | |
MOV AL, [SI] | |
CMP AL, [SI+1] | |
JNG noswap | |
XCHG AL, [SI+1] | |
XCHG AL, [SI] | |
noswap: | |
INC SI | |
DEC CH | |
JNZ inner_loop | |
DEC CL | |
JNZ outer_loop | |
RET | |
sortArray ENDP | |
;--------------------------------------------------------------------------- | |
;---------------------------- SPLIT ARRAY ---------------------------------- | |
;--------------------------------------------------------------------------- | |
splitOddEven PROC | |
;----- EVEN ----- | |
MOV SI, OFFSET arr | |
MOV DI, OFFSET even_arr | |
MOV CL, count | |
MOV CH, 00 | |
up1: | |
MOV AL, [SI] | |
MOV BL, AL | |
AND AL, 01 | |
CMP AL, 00 | |
JNE noteven | |
MOV [DI], BL | |
INC DI | |
INC CH | |
noteven: | |
INC SI | |
DEC CL | |
JNZ up1 | |
MOV even_count, CH | |
;----- ODD ----- | |
MOV SI, OFFSET arr | |
MOV DI, OFFSET odd_arr | |
MOV CL, count | |
MOV CH, 00 | |
up2: | |
MOV AL, [SI] | |
MOV BL, AL | |
AND AL, 01 | |
CMP AL, 01 | |
JNE notodd | |
MOV [DI], BL | |
INC DI | |
INC CH | |
notodd: | |
INC SI | |
DEC CL | |
JNZ up2 | |
MOV odd_count, CH | |
RET | |
splitOddEven ENDP | |
;--------------------------------------------------------------------------- | |
;---------------------- FIND SMALLEST AND LARGEST NOS ---------------------- | |
;--------------------------------------------------------------------------- | |
findLS MACRO array, cnt, small, large | |
LOCAL increment | |
MOV SI, OFFSET array | |
MOV AL, [SI] | |
MOV small, AL ; First element | |
MOV CL, cnt | |
DEC CL | |
increment: | |
INC SI | |
DEC CL | |
JNZ increment | |
MOV AL, [SI] | |
MOV large, AL ; Last element | |
findLS ENDM | |
;--------------------------------------------------------------------------- | |
;---------------------------- MAIN PROGRAM --------------------------------- | |
;--------------------------------------------------------------------------- | |
MAIN PROC | |
MOV AX, @data | |
MOV DS, AX | |
CALL takeUserInput | |
PRINTN | |
PRINTN | |
PRINT "ARRAY: " | |
printArray arr, count | |
CALL sortArray | |
PRINTN | |
PRINT "SORTED ARRAY: " | |
printArray arr, count | |
CALL splitOddEven | |
PRINTN | |
PRINTN | |
PRINT "EVEN ARRAY: " | |
printArray even_arr, even_count | |
PRINTN | |
PRINT "ODD ARRAY: " | |
printArray odd_arr, odd_count | |
findLS even_arr, even_count, even_small, even_large | |
PRINTN | |
PRINTN | |
PRINT "LARGEST EVEN NO: " | |
printArray even_large 1h | |
PRINTN | |
PRINT "SMALLEST EVEN NO: " | |
printArray even_small 1h | |
findLS odd_arr, odd_count, odd_small, odd_large | |
PRINTN | |
PRINTN | |
PRINT "LARGEST ODD NO: " | |
printArray odd_large 1h | |
PRINTN | |
PRINT "SMALLEST ODD NO: " | |
printArray odd_small 1h | |
MOV AH, 4Ch | |
INT 21h | |
MAIN ENDP | |
END MAIN | |
;--------------------------------------------------------------------------- | |
;---------------------------- END OF PROGRAM ------------------------------- | |
;--------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment