print odd and even numbers

Reply

Join Date: Mar 2005
Posts: 1
Reputation: pro32 is an unknown quantity at this point 
Solved Threads: 0
pro32 pro32 is offline Offline
Newbie Poster

print odd and even numbers

 
0
  #1
Mar 3rd, 2005
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.

  1. .data
  2.  
  3. arrayInt DWORD 10 dup(0)
  4. sentence BYTE "Please input a three digit integer: "
  5.  
  6. .code
  7. main PROC
  8.  
  9. mov esi, 0
  10. mov ecx, LENGTHOF sentence
  11.  
  12. L1:
  13. mov al, sentence[esi]
  14. call WriteChar
  15. inc esi
  16. Loop L1
  17.  
  18. ;Filling array
  19. mov ecx , LENGTHOF arrayInt
  20. mov esi, 0
  21.  
  22. L2:
  23. call ReadInt
  24. mov arrayInt[esi], eax
  25. add esi, 4
  26. Loop L2
  27.  
  28. ;Sorting array
  29. L3:
  30. mov edx, 0 ; bubble flag
  31. mov ecx, LENGTHOF arrayInt
  32. dec ecx
  33. mov esi, 0 ; first elemennt
  34. InnerLoop:
  35. mov eax, arrayInt[esi]
  36. cmp eax, arrayInt[esi+4]
  37. jle OutLoop
  38.  
  39. ; If first element grater then second switch their places
  40. mov ebx, arrayInt[esi+4]
  41. mov arrayInt[esi], ebx
  42. mov arrayInt[esi+4], eax
  43. mov edx, 1 ; set bubble flag
  44. OutLoop:
  45. add esi, 4
  46. Loop InnerLoop
  47. cmp edx, 1
  48. je L3
  49.  
  50.  
  51. ; Printing array
  52. mov ecx, LENGTHOF arrayInt
  53. mov esi, OFFSET arrayInt
  54. L4:
  55. mov eax, [esi]
  56. add esi, 4
  57.  
  58. call WriteInt
  59. call CrLf
  60. Loop L4
  61.  
  62. exit
  63. main ENDP
  64. END main
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: print odd and even numbers

 
0
  #2
Mar 4th, 2005
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++)
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC