Need Help! Print odd and even numbers

[b][red]This message was edited by pro32 at 2005-3-3 13:31:30[/red][/b][hr]
My program sorts numbers inputed by users and print them. But I also want it to print only odd and only evens. Any help is appreciated

.data

arrayInt DWORD 10 dup(0)
sentence BYTE "Please input a three digit integer: "

.code
main PROC

mov esi, 0
mov ecx, LENGTHOF sentence

L1:
mov al, sentence[esi]
call WriteChar
inc esi
Loop L1

;Filling array
mov ecx , LENGTHOF arrayInt
mov esi, 0

L2:
call ReadInt
mov arrayInt[esi], eax
add esi, 4
Loop L2

;Sorting array
L3:
mov edx, 0 ; bubble flag
mov ecx, LENGTHOF arrayInt
dec ecx
mov esi, 0 ; first elemennt
InnerLoop:
mov eax, arrayInt[esi]
cmp eax, arrayInt[esi+4]
jle OutLoop

; If first element grater then second switch their places
mov ebx, arrayInt[esi+4]
mov arrayInt[esi], ebx
mov arrayInt[esi+4], eax
mov edx, 1 ; set bubble flag
OutLoop:
add esi, 4
Loop InnerLoop
cmp edx, 1
je L3


; Printing array
mov ecx, LENGTHOF arrayInt
mov esi, OFFSET arrayInt
L4:
mov eax, [esi]
add esi, 4

call WriteInt
call CrLf
Loop L4

exit
main ENDP
END main


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories