Hi, I'm pretty new to writing stuff in Assembler . Now I'm trying to run some code that puts the odd numbers from an array to a second one, and the even numbers to a third one.
I don't really know how to make the transfer. I tried with MOVSB and STOSB but it didn't work out. This is what I've done so far...

``````array db 8,2,3,4,5,6,7,9,12,15
odd db "Odd \$ "
even db "Even \$ "
Modd db 6 dup(?)
Meven db 6 dup(?)

.code
.startup

lea si,array
lea di,even
mov cx,0Ah
loops:
lodsb
mov bl,al
and bl,0001b
cmp bl,0001b
jne yes
je no
jcxz leave
dec cx
loop loops

yes:
mov ah,2
lea dx,even
;movsb
mov ah,9
int 21h

loop loops

no:
mov ah,2
lea dx,odd
mov ah,9
int 21h
loop loops

leave:
mov ah,0
int 16h
int 20h``````

Some initial recommendations...

``````;;;lodsb  mov bl,al
mov bl,[si]
inc si
test   bl,0001b
;;;and    bl,0001b
;;;cmp bl,0001b
jne yes
;;;je no
jmp no
;;; CODE NEVER GETS HERE!!!
jcxz leave``````

You loop but what happens on the last itertion? Code flows into yes.

To move the code

``````mov al,[si]
inc si
mov [di],al
inc di``````
``````;lodsb
mov al,[si]
inc si``````
``````;stosb
mov [di],al
inc di``````

Good old fundamentals of low-level array manipulation, implemented the code,
does no printing, viewable someway nonetheless.

``````bits 16
org 100h

start:
mov si, arr ; our array of unsorted odds and evens
mov di, odd
mov bx, even
cld
mov cx, arr_len
start_l:
lodsb
test al, 0x1 ; test lsb to determine if it is set
jnz odd_eri
jz even_eri
start_lr1:
loop start_l
jmp exit
odd_eri:
mov [di], al ; al contains odd value, store away in odd
inc di
jmp start_lr1
even_eri:
mov [bx], al ; al contains even value, store away in even
inc bx
jmp start_lr1
exit:
int 0x20 ; typical .COM termination

odd times 0x10 db 0x0
even times 0x10 db 0x0
arr db 1,2,3,4,5,6,7,8,9,10
arr_len equ \$-arr``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.