Re: Read N from keybord. Double even numbers. Using LOOP instruction
- From: //\\\\o//\\\\annabee <Wannabee@xxxxxxxxxxxx>
- Date: Tue, 27 Feb 2007 02:20:26 -0000
På Tue, 27 Feb 2007 02:08:10 -0000, skrev //\\o//\\annabee <Wannabee@xxxxxxxxxxxx>:
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.
It would not work, because there may be set bits in later 32 bit words.
I only hacked something in a hurry, and it needs to have more eyes on it, but it seem to work for the test case.
[LargeNumber: ? #100]
Main:
;test data
mov D$LargeNumber 0-1
mov D$LargeNumber+4 0-1
mov D$LargeNumber+8 0_FFFF_0000
mov D$LargeNumber+24 0_FFFF_0000
Routine:
mov eax 0
@Next:
shl D$LargeNumber+eax*4, 1
jnc @AreWeDone
L0:
inc eax
shl D$LargeNumber+eax*4, 1
inc D$LargeNumber+eax*4
jc L0<
@AreWeDone:
inc eax
While D$LargeNumber+eax*4 = 0 | inc eax | end_While
cmp eax 100 | jb @Next
.
- References:
- Read N from keybord. Double even numbers. Using LOOP instruction
- From: aeter
- Re: Read N from keybord. Double even numbers. Using LOOP instruction
- From: //\\\\o//\\\\annabee
- Read N from keybord. Double even numbers. Using LOOP instruction
- Prev by Date: Re: Read N from keybord. Double even numbers. Using LOOP instruction
- Next by Date: Re: Help me about this question.
- Previous by thread: Re: Read N from keybord. Double even numbers. Using LOOP instruction
- Next by thread: Printer command language support CMY or CMYK color spaces??
- Index(es):
Relevant Pages
|