0

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
2
Contributors
1
Reply
5
Views
12 Years
Discussion Span
Last Post by 1o0oBhP
0

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++)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.