<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 24 Nov 2009 00:16:38 +0000
From   : rs423@... (Mick Champion)
Subject: ASL/LSR

Anders Carlsson wrote:
> Michael Firth wrote:
>
>   
>> LSR = Logical Shift Right, equivalent to a divide by 2
>> ASL = Arithmetic Shift Left, equivalent to a multiply by 2
>>     
>
> While we are on the topic, another construct you sometimes want to do is 
> count how many bits in a byte are enabled. This is ideally done with either 
> of these instructions:
>
> LDX #0
> LDA data
> .loop
> LSR
> BCC check
> INX
> .check
> BNE loop
> RTS
>
> Perhaps this is an obvious use, but the example points out that LSR always 
> changes the carry flag even if the bit shifted out is a zero.
I thought that the carry flag corresponded to the byte shifted out.


>  It also points 
> out LSR affects the Z flag as well, so when the accumulator equals zero, the 
> BNE automatically fails without the need for an extra CMP #00.
So if you ASL a memory location rather than the accumulator, you can use 
BNQ and BEQ? Okay.


>  Actually a 
> good study of which flags each instruction will change is beneficial if you 
> try to write effective machine code. On a computer with plenty of memory to 
> use you have less reason to consider every byte but I imagine even then it 
> sometimes can get tight, e.g. if you try to patch an existing ROM.
>   
I have the Advanced user guide by Bray, Dickens and Holmes which has all 
the exit flags. For zero, it says set if result = zero. What result 
would that be though. The bit shifted out? No need to answer that, I'll 
do a test.


Cheers,



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