Re: Read N from keybord. Double even numbers. Using LOOP instruction
- From: //\\\\o//\\\\annabee <Wannabee@xxxxxxxxxxxx>
- Date: Tue, 27 Feb 2007 02:08:10 -0000
På Sun, 25 Feb 2007 22:35:47 -0000, skrev aeter <A.eleter@xxxxxxxxx>:
Hello im new to this group and new to assembly langage.
i have a simple question how can i double even number?
Same way you double "any" number in a pc.
mov eax D$number // likly to be "mov eax, [Number]" in masm
shl eax 1
or just
shl D$Number 1
In a computer the answer to your question is never final, because "numbers" can have magnitudes so large _no computer_ can express. But for the avarage case, you can do with the above.
This means to shift the number left by 1 place. One place left in the binary system, means *2.
So, 01 (binary) = 0*2^1 + 1*2^0 = 1 (decimal)
==> shl 1 (whn shiftet left by 1)
==> gives 10b = (1*2^1 + 0*2^0)d
(any number multiplied by 0 = 0, and any number with an exponent of 0 is 1
^ takes presidens over * )
This shifting left can be extended beyound 32 bit, but in that case you need to make sure that any bit shiftet out of the lower 32 bit word, is shifted into the upper 32 bit word, for as many 32 bit words you need to hold the number.
[LargeNumber: ? #100]
Main:
mov D$LargeNumber 0-1
mov D$LargeNumber+4 0-1
mov D$LargeNumber+8 0_FFFF_0000
mov eax 0
@Next:
shl D$LargeNumber, 1
jnc @Done
L0:
inc eax
shl D$LargeNumber+eax*4, 1
inc D$LargeNumber+eax*4
jc L0<
I am not 100% sure this would work, but it should at least give you the idea.
.
- Follow-Ups:
- Re: Read N from keybord. Double even numbers. Using LOOP instruction
- From: //\\\\o//\\\\annabee
- Re: Read N from keybord. Double even numbers. Using LOOP instruction
- References:
- Prev by Date: Re: Advanced Linux Programming
- 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
|