<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 24 Nov 2009 00:40:09 +0000
From   : robert@... (Rob)
Subject: Quine

On 24/11/2009, Mick Champion <rs423@...> wrote:
>> Another common construct is to combine ASLs and ROLs to be able to
>> multiply with variables bigger than 8 bits - an "ASL loc" followed by a
>> "ROL loc+1" does a 16 bit multiply by 2.
>>
> Now I'm lost again. I thought that both ROL and ASL use the carry flag
> for output only.

No... ROL does this...

,----------------------------------------------------------.
`--<< C << b7 << b6 << b5 << b4 << b3 << b2 <<b1 << b0 <<--'

i.e.  bit 7 shifts into the carry, and the carry shifts into bit 0.

Whereas ASL does this

   C << b7 << b6 << b5 << b4 << b3 << b2 <<b1 << b0 << 0

i.e. bit 7 shifts into the carry, but a zero shifts into bit 0.

So
ASL lsb
ROL msb

shifts the lsb left one, putting bit 7 into the carry
then shifts the msb left one, putting the carry (ex bit 7 of lsb) into bit 0

So you've just multiplied 16 bits by two in two instructions.

Obviously you can chain on another two ROLs to multiply a 32-bit number by two.

HTH

Rob
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>