Assembly programming language is a low-level computer programming language that uses mnemonic to represent each low-level machine instruction. The below program illustrates how to separate even and odd numbers using assembly language.
DATA SEGMENT
org 1000h
array db 11h, 22h, 33h, 44h, 55h, 66h, 77h, 88h, 99h, 10h
org 2000h
evn db ?
org 3000h
odd db ?
data ends
CODE SEGMENT
assume cs:code, ds:data
start: mov ax,data
mov ds, ax
lea si, array
lea di, odd
mov ax, 00h
mov cl, 0ah
up: mov al, [si]
mov bl, 02
div bl
cmp ah, 00h
je l1
mov a1, [si]
mov [di], al
inc di
l1: inc si
dec cl
jnz up
lea si, array
lea di, evn
mov cl, 0ah
up1: mov al, [si]
mov bl, 02h
div bl
cmp ah, 00h
jne l2
mov al, [si]
mov [di], al
inc di
l2: inc si
dec cl
jnz up1
skip: mov ah, 4ch
int 21h
code ends
end start
The above program illustrates how to separate even and odd numbers using assembly language. We first define the array of numbers we want to separate and then defines address to store even numbers and address to store odd numbers. Here, we have used address 2000h to store even numbers and address 3000h to store odd numbers.
Also read: Best websites to Learn Coding Online
The output of the program to separate even and odd numbers using assembly language is shown below.
Output -
g=0000 0048
AX=4C10 BX=0002 CX=3000 DX=0000
-d 2000
076A: 2000 22 44 66 88 10
-d 3000
076A: 3000 33 55 77 99
The above program illustrated how to separate even and odd numbers using assembly language program.