Re: Read N from keybord. Double even numbers. Using LOOP instruction
- From: "SpooK" <keith@xxxxxxxxxxx>
- Date: 26 Feb 2007 08:31:56 -0800
On Feb 26, 1:23 am, "Rod Pemberton" <do_not_h...@xxxxxxxxxxx> wrote:
"SpooK" <k...@xxxxxxxxxxx> wrote in message
news:1172460299.440910.217600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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)
I wasn't sure what the OP wanted, he asked about doubling a number but his
code isn't close. He could've been interested in shrd/shld for all I could
tell.
But, as to your code, any time you multiply by 2 (i.e., double a number) the
resulting number is even. The definition of even is divisible by two (and
since you just multiplied by two...). Therefore, the 'and al,0xFE' is
unecessary since bit 0 will be 0 due to the shl, i.e., it's even. Perhaps
you were thinking about masking rol/ror/rcr/rcl which could shift in the
carry? Or, perhaps, you were thinking about masking division using shr/sar
to ensure the number was even?
;)
I'm sorry...
Rod Pemberton
Actually, just very little sleep because of my newborn son :)
Thanks for catching that though ;)
.
- Follow-Ups:
- References:
- Prev by Date: Re: Printer command language support CMY or CMYK color spaces??
- Next by Date: Re: Read N from keybord. Double even numbers. Using LOOP instruction
- Previous by thread: Re: Read N from keybord. Double even numbers. Using LOOP instruction
- Next by thread: Re: Read N from keybord. Double even numbers. Using LOOP instruction
- Index(es):
Relevant Pages
|