My program takes input from users, sort them and print out the result. But I would also like for it to only print out odd numbers and print out even numbers.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

not done assembly for a while but...

in the array loop if you have a flag for odd / even and XOR it every time the loop goes round it will switch from odd to even. Then test the flag to see whether to print or not (an algorithm I use in c++)

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.