[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ROL Instruction
On 15 Mar 2004 09:28:14 GMT, mjmahon@aol.com (Michael J. Mahon) wrote:
> If you want to simulate a ROL that does not include carry,
> it is only necessary to preset the carry bit to the high bit
> of the shifted byte. For example, if the A register is being
> shifted, then preceding the ROL with a CMP #$80 will cause
> the ROL to shift the high bit to the low bit position.
Doing the same for ROR is slightly more involved. The quickest
and shortest way (I think) is
LSR ; c contains lsb
BCC .1 ; lsb was clear, skip next instruction
ADC #$7F ; add #$80 to set high bit
.1 ; program continues here
The ADC can be replaced with ORA #$80 but the ADC version
has the advantage of leaving the carry in a known state (C=0)
whether the branch was taken or not.
Quiz: what's the shortest 6502 code that will swap nibbles
in a byte (e.g. $6D will become $D6, $81 will become $18, etc.)?
Paul Guertin
pg@sff.net