Jump to content



0

Question about lsr (and related)...


17 replies to this topic

#1 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Jan 3, 2005 6:46 PM

I've been using this page: http://www.6502.org/...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?

#2 Kroko OFFLINE  

Kroko

    Moonsweeper

  • 391 posts
  • Location:Germany

Posted Mon Jan 3, 2005 7:03 PM

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

#3 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Jan 3, 2005 7:09 PM

Kroko said:

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?

#4 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Mon Jan 3, 2005 7:23 PM

Hi there!

vdub_bobby said:

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

#5 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Mon Jan 3, 2005 7:24 PM

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.

#6 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Mon Jan 3, 2005 7:29 PM

Cybergoth said:

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:

#7 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Jan 3, 2005 7:31 PM

Nukey Shay said:

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.

Cybergoth said:

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?

#8 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Mon Jan 3, 2005 7:37 PM

I dunno...I'm just a hacker :party: :D

#9 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Mon Jan 3, 2005 7:42 PM

Hi there!

Nukey Shay said:

Cybergoth said:

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

#10 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Jan 3, 2005 7:57 PM

Cybergoth said:

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 :)

#11 Andrew Davie OFFLINE  

Andrew Davie

    Stargunner

  • 1,314 posts
  • Location:Tasmania

Posted Mon Jan 3, 2005 8:25 PM

vdub_bobby said:

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?

#12 Cybergoth OFFLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Mon Jan 3, 2005 8:57 PM

Hi there!

Andrew Davie said:

vdub_bobby said:

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

#13 Tom OFFLINE  

Tom

    Moonsweeper

  • 449 posts
  • Location:Switzerland

Posted Mon Jan 3, 2005 9:38 PM

And what do other emus ? Modify the ROM ? Early versions of VisualBoyAdvance did that too, this was a way to check wether a program was running on an amulator or on real hardware =)

#14 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Wed Jan 5, 2005 4:34 AM

Tom said:

And what do other emus ?
No, Manuel was just joking. Actually only PCAE has this (confirmed?) bug.

#15 carlsson OFFLINE  

carlsson

    Chopper Commander

  • 157 posts
  • Location:Västerås, Sweden

Posted Fri Jan 7, 2005 5:52 PM

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... ;)

#16 carlsson OFFLINE  

carlsson

    Chopper Commander

  • 157 posts
  • Location:Västerås, Sweden

Posted Fri Jan 7, 2005 5:53 PM

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... ;)

#17 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Fri Jan 7, 2005 6:51 PM

carlsson said:

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.

#18 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Sat Jan 8, 2005 1:46 AM

...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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users