Assembly question: About displaying even nos

I need to enter 10 positive integers and display only the even nos from the 10 nos entered.
I cant use .IF,.WHILE,.REPEAT directives
RandafernsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dimitryCommented:
So what is the problem ? Please post your code that doesn't work.
0
RandafernsAuthor Commented:
I was wondering if anyone could help me..as i just cant do it..i mean taking the integers in is fine..like this is alli could get..am new to assembly

TITLE Even nos       (Evennos.asm)


INCLUDE Irvine32.inc

.data
prompt BYTE "Enter 10 positive integers: ",0
buffer  BYTE 50 dup(0)


.code
main PROC
; listing the evens nos from the postive integers added.:
      
; Ask the user to input 10 postive integers:
      call Clrscr                    ; clear screen
      mov  edx,OFFSET prompt            ; "Enter 10 postive integers: "
      call WriteString
      

      exit
main ENDP
END main



0
dimitryCommented:
It is against E-E policy to do homeworks for students. However, there is no any reason not to help you to find the solution.
So what is the problem ?
You do not understand the algorithm how to check if number is even ?
The simplest way in assembler to 'and' it with 01h and to check if the result is 0 or 1. In case of 1 the number is odd...
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

RandafernsAuthor Commented:
well..thanks dimitry..
obviously was not expecting the entire thing..just needed help with the algorithm
i have a basic idea that i can use compare to MOD 2 and check..but if u could help me out a bit with the algorithm, it would be really nice..

Thanks.
0
dimitryCommented:
Usually in C people are doing:
if( (num % 2) == 0 )
  printf("Even number: %d\n",num);

However, % - MOD operation is VERY heavy and in case of '% 2' is obsolete.
You need to do:
if( (num & 0x1) == 0 )
  printf("Even number: %d\n",num);

Why it is Ok ?
In binary presentation even number will be like 'bbbbbbbbb....bbb0' and odd will be 'bbbbbbbbb...bbb1'.
So checking last bit for 1 gives you ability to distinguish between even and odd number.
Now, in x86 assembler there is test command that will do 'and' without changing the number itself.

So assuming that 'si' contains pointer to array element then you need to do:
  tst [si], 01h
  jnz oddNum
  ... print .. [si] number
oddNum:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RandafernsAuthor Commented:
Hi dimitry
thanks that was really helpful..
I'll use the test instruction and check
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Assembly

From novice to tech pro — start learning today.