Date : Tue, 24 Nov 2009 01:12:21 +0000
From : rs423@... (Mick Champion)
Subject: Quine
Rob wrote:
> 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.
>
Perfect. I get it at last. What confused me with the ROR or L's was
there is only one carry so I wrongly thought bit 7 became bit 0 or the
other way around. This seemed pointless. Now it all makes sense. Is the
exit carry bit placed on the stack until the value in carry bit is
written to the shifting byte? Thanks, and sorry for being so dumb. I'd
turn on the BEEB again and try it but I've have had quite enough PSU
smoke for 1 day. Thanks to the posts on this list, I knew it would
happen one day and didn't jump out of my skin.... much! :-)
Many thanks,
Mick