| | |
print odd and even numbers
![]() |
•
•
Join Date: Mar 2005
Posts: 1
Reputation:
Solved Threads: 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.
Assembly Syntax (Toggle Plain Text)
.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++)
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++)
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Similar Threads
- Loop counting odd and even numbers (C++)
- Print Prime Numbers(using for loop) (C)
- Pointers and Sorting Array by Even and Odd numbers (C)
- Odd numbers in C++? (C++)
- Adding the sum of odd numbers. Please help (Visual Basic 4 / 5 / 6)
Other Threads in the Assembly Forum
- Previous Thread: looking for quicksort in assembly 8085
- Next Thread: EM_SETSEL message not highlighting selection
| Thread Tools | Search this Thread |





