Re: Read N from keybord. Double even numbers. Using LOOP instruction



On Feb 26, 10:58 am, "aeter" <A.ele...@xxxxxxxxx> wrote:
Thank you All..u guys are the best..im going to work on it..concerning
doubling the even numbers is like: S = 1 + (2+2) + 3 + (4+4) + 5 +
(6+6) +.....N

In that case, this should work

;##### DOUBLE ALL THE EVEN NUMBERS IN A GIVEN RANGE #####

;Double all the even numbers
xor eax,eax ;Sum Holder
mov ecx,10 ;Counter and Number, all in one!!!

DOUBLE_LOOP:
test ecx,1
jnz ODD

;Process an "Even" Number
mov edx,ecx
shl edx,1
add eax,edx
loop DOUBLE_LOOP
jmp END

;Process an "Odd" Number
ODD:
add eax,ecx
loop DOUBLE_LOOP

;Continue on with the rest of the code...
END:
;##### WASN'T THAT FUN??? #####

I would double-check the use of that "test" instruction, I'm kind of
rusty at it ;)

.



Relevant Pages