<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 20 Nov 2009 21:09:37 +0000
From   : mfirth@... (Michael Firth)
Subject: Quine

Mick Champion wrote:
> Jonathan Graham Harston wrote:
>   
>>> Message-ID: <4B0538B1.4060506@...>
>>>     
>>>       
>>  
>> Mick Champion wrote:
>>   
>>     
>>> right to add another if I can work out how GOTO is tokenised. E5
>>> followed by what? ;-)
>>>     
>>>       
>>  
>> E5 followed by the tokenised line number. See
>> http://mdfs.net/Docs/Comp/BBCBasic/Line/Numbers3
>>   
>>     
> Thanks. I've done a few programs in assembly language, but never got my 
> head around things like LSR (logical shift right). 
LSR = Logical Shift Right, equivalent to a divide by 2
ASL = Arithmetic Shift Left, equivalent to a multiply by 2

The main difference between LSR/ASL and ROR/ROL is what happens with the 
carry.

With the ROx functions, the LSB or MSB becomes the carry, and the carry 
becomes the LSB or MSB. However, with LSR and ASL, the bit that is 
shifted out becomes the carry, but a zero is shifted in, rather than the 
old carry.

> In your decode 
> listing, you do this 4 times. If I wanted to multiply, off the top of my 
> head, I'd do something like
>
> CLC
> LDA byte1
> LDX #0
> .loop
> ADC byte1
> STA byte1
> BCC a
> INC byte2
> .a
> INX
> CPX#4
> BNE loop
>
>
>
> Am I missing something?
>
>   

You can use ASL to multiply, for example:

ASL A
STA temp
ASL A
ASL A
CLC
ADC temp

Is equivalent to a multiply by 10.

A common construct to see in BBC (and probably other 6502) assembler is 
4 ASLs or LSRs, which do a divide or multiply by 16, useful for moving 
data between the nibbles of bytes.

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.

Regards

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