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



On Feb 25, 4:35 pm, "aeter" <A.ele...@xxxxxxxxx> wrote:
Hello im new to this group and new to assembly langage.
i have a simple question how can i double even number?
my code so far:
INCLUDE Irvine32.inc
.code
main PROC ; Label for the start of the main program
mov edx, 0
mov ebx, 1
mov ecx, 10 ;loop can be excuted 10 times
label1:
add edx, ebx
add ebx, 1
inc ebx
jmp label1
loop label1

exit
main ENDP
END main
thanks

First off, your code has an infinite loop because you have a hard jump
in there before the actual loop instruction. The LOOP instruction is a
counter and condition jump instruction rolled into one.

Your code can be made much cleaner. You are using the binary number
system, each place holder is double of the last. Simply shift the
desired number left by 1 bit.

If you need to check if the number is even prior to performing the
shift/double, simply test the first bit to see if it is 1 or 0. If it
is 0, the number is even.

If you need to double a number and force it to be even, simply mask
the same first bit after the shift/double so that it will be 0.

Here is a simple example of how to double a number while keeping it
even.

;EAX = Number to Double
shl eax,1 ;Double the number
and al,0xFE ;Mask the lowest bit to be 0 (even)

Good luck on your assembly language learning path ;)

.



Relevant Pages