Jump to content
IGNORED

Question about lsr (and related)...


Recommended Posts

I've been using this page: http://www.6502.org/tutorials/6502opcodes.htm as a handy-dandy reference. I just now happened to read this section a little closer:

 

LSR (Logical Shift Right)



Affects Flags: S Z C



MODE           SYNTAX       HEX LEN TIM

Accumulator   LSR A         $4A  1   2

Zero Page     LSR $44       $46  2   5

Zero Page,X   LSR $44,X     $56  2   6

Absolute      LSR $4400     $4E  3   6

Absolute,X    LSR $4400,X   $5E  3   7





LSR shifts all bits right one position. 0 is shifted into bit 7 and the original bit 0 is shifted into the Carry.

 

What does lsr absolute do? Just shift bit 0 of that memory location into the carry and take 6 cycles doing it?

Link to comment
Share on other sites

Hi !

 

are you interested in what is going on inside the CPU ?

 

1 fetch opcode, increment PC

2 fetch low byte of address, increment PC

3 fetch high byte of address, increment PC

4 read from effective address

5 write the value back to effective address and do the operation on it

6 write the new value to effective address

Link to comment
Share on other sites

Hi !

 

are you interested in what is going on inside the CPU ?

 

1  fetch opcode, increment PC

2  fetch low byte of address, increment PC

3  fetch high byte of address, increment PC

4  read from effective address

5  write the value back to effective address and do the operation on it

6  write the new value to effective address

 

That's interesting, thanks. But what I really want to know is: you can't do a logical shift on ROM, right? So what does the CPU do when it comes across 'lsr absolute'?

 

Tell me where I am being stupid here:

Command  Action

lsr  shifts the accumulator one bit to the right

lsr ZP  shifts the zero-page mem location 1 bit to the right

lsr ZP,X	shifts the indexed zero-page mem location

lsr absolute	??

lsr abolute,X	??

What goes in the question marks?

Link to comment
Share on other sites

Hi there!

 

That's interesting, thanks.  But what I really want to know is:  you can't do a logical shift on ROM, right?  So what does the CPU do when it comes across 'lsr absolute'?

 

It just moves the highest bit into the carry. For example you can do

 

lsr swchb

 

to check the reset switch.

 

On a C64 or other computers it certainly makes more sense as they have RAM mapped outside the zeropage.

 

Greetings,

Manuel

Link to comment
Share on other sites

I think he was trying to say that with Rom addresses, steps 5 and 6 won't work. So the value at the address stays the same...and the carry stays the same. 3 NOP instructions would take as long and use the same number of bytes.

However, you can intentionally stretch a zero-page address to be worked on in absolute addressing instead (say, if you wanted to burn a couple extra cycles). LSR $0080 does the same thing as LSR $80...it just takes a bit longer to perform.

Link to comment
Share on other sites

I think he was trying to say that with Rom addresses, steps 5 and 6 won't work.  So the value at the address stays the same...and the carry stays the same.  3 NOP instructions would take as long and use the same number of bytes.

However, you can intentionally stretch a zero-page address to be worked on in absolute addressing instead (say, if you wanted to burn a couple extra cycles).  LSR $0080 does the same thing as LSR $80...it just takes a bit longer to perform.

 

It just moves the highest bit into the carry. For example you can do

 

lsr swchb

 

to check the reset switch.

 

So...it does or it doesn't change the carry?

Link to comment
Share on other sites

Hi there!

 

It just moves the highest bit into the carry. For example you can do  

 

lsr swchb

 

to check the reset switch.

Oops :P I didn't think that it would affect the carry status :lol:

 

Hm... as ususal, I made a mistake though, as LSR certainly moves the lowest into the carry - just as one would expect...

 

Hehe, I just realized this when wondering why I don't rather use BIT abs... :dunce:

 

Greetings,

Manuel

Link to comment
Share on other sites

Hm... as ususal, I made a mistake though, as LSR certainly moves the lowest into the carry - just as one would expect...

 

Hehe, I just realized this when wondering why I don't rather use BIT abs... :dunce:

 

Greetings,

Manuel

 

Thanks everyone. The answer turns out to be pretty much what I figured, but at first I was boggled, staring at 'lsr absolute' and wondering what in the world was going on :)

Link to comment
Share on other sites

Hi there!

 

Thanks everyone.  The answer turns out to be pretty much what I figured, but at first I was boggled, staring at 'lsr absolute' and wondering what in the world was going on :)

 

Self-modifying ROM code, anyone?

 

Only emulator correctly emulating this is PCAE :lol:

 

Greetings,

Manuel

Link to comment
Share on other sites

For what it's worth, absolute or non-ZP indexed STA/STX/STY, ROL/ROR/ASL/LSR and INC/DEC should all be just as pointless in a ROM-only address space? In particular the ST* instructions, as they don't even change any register flags...  ;)

 

They might be useful as efficient ways to waste cycles :)

 

Check out Andrew Davie's post to Stella.

Link to comment
Share on other sites

...or bankswitching. $xFF8 and $xFF9 (where x = a odd digit) will trigger a bankswitch using the F8 scheme, and it doesn't matter how those addresses are accessed.

 

BTW IIRC $2D to $2F (and their mirrors) cannot be written to...so you can use STA $2F to waste 3 cycles in 2 bytes...or 5 cycles by using DEC $2F.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...