Left and Right Shifts and Absolute Addressing

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
Post Reply
gmcastil
Posts: 25
Joined: 19 Mar 2017

Left and Right Shifts and Absolute Addressing

Post by gmcastil »

I've been working on my processor quite a bit over the last couple days and started implementing the ASL and LSR opcodes using absolute addressing mode. I observed that for other instructions that use the ALU (e.g., ADC) that mode takes 4 clock cycles to complete. Assuming that ASL and LSR are using the ALU as well, it seems odd to me that those operations would take longer.

Is there a reason it takes an extra two clock cycles for those two instructions to execute relative to the others? Thanks.
gmcastil
Posts: 25
Joined: 19 Mar 2017

Re: Left and Right Shifts and Absolute Addressing

Post by gmcastil »

I may have answered my own question - the block diagram for the processor shows the ALU connected to an adder for some reason. Perhaps the ALU needed to use that to add something to the shifted result and then another clock cycle to register it back in the processor?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Left and Right Shifts and Absolute Addressing

Post by GARTHWILSON »

I think at least part of your answer lies in the '816 data sheet:
AbsRMWcycles.gif
65cycleNotes.gif
It takes an extra cycle to do the operation and another to do the write-back since the result does not go in a processor register. Note that "data high" in the table (in the column second from the right edge) only applies to the '816 and only when you have its accumulator in 16-bit mode, and does not apply to the '02.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Left and Right Shifts and Absolute Addressing

Post by Dr Jefyll »

gmcastil wrote:
other instructions that use the ALU (e.g., ADC) that mode takes 4 clock cycles to complete.
Right. ADC requires just a single access to memory at the specified address.

In contrast, ASL LSR ROL ROR INC and DEC are Read-Modify-Write instructions. They conclude by taking what's at the specified address, altering it, and putting it back. The "alter it and put it back" is what adds the two extra cycles. You can see this in the chart excerpt Garth posted.

(ADC operates on the Accumulator -- an internal register. The "alter it and put it back" doesn't require access to memory.)
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
gmcastil
Posts: 25
Joined: 19 Mar 2017

Re: Left and Right Shifts and Absolute Addressing

Post by gmcastil »

Yeah, I completely missed that in the instruction description - for some reason it completely escaped me that I needed to do something with the result. I suppose that's what I deserve working on code at 3:00 AM. I need to go back and modify some of my design now.
Post Reply