how to write this in assembly
if(x is even)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
The basic structure of a while loop is also shown here: http://openstudy.com/study#/updates/5124d00be4b086b98ebdbc10
The loop body can be done in two ways: slow and faster. I'll explain the slow method in more details and I'll give some hints for the faster method.
For the slow method, you'll need a division. Divisions can be a bit complex to use. You'll need to put the dividend into two registers: the upper half in edx and the lower half in eax. Then you can use the div instruction with the divisor as argument. The quotient will be in eax and the remainder in edx.
So in code. Let's assume x is an unsigned int (so the upper half is all 0s) and is located in esi:
mov edx, 0
mov eax, esi
mov edi, 2 # div only works on registers and
# memory locations
cmp edx, 1
jnz endif # if the compare is zero, the number
# is even so we need to jump when
# it's not
mov esi, eax # eax is still the result of the
# previous division. so no need
# to redo it
For the fast method, you can check certain bits to see if a number is even/odd. Also, division by a power of 2 can be replaced with a fast instruction.
Probably better for the comparisson:
cmp edx, 0
is it going to loop until the number is eqqual or less than 1.Or it will only show register output once?