vdub_bobby Posted January 4, 2005 Share Posted January 4, 2005 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? Quote Link to comment Share on other sites More sharing options...
Kroko Posted January 4, 2005 Share Posted January 4, 2005 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 Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 4, 2005 Author Share Posted January 4, 2005 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? Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted January 4, 2005 Share Posted January 4, 2005 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 Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted January 4, 2005 Share Posted January 4, 2005 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. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted January 4, 2005 Share Posted January 4, 2005 It just moves the highest bit into the carry. For example you can do lsr swchb to check the reset switch. Oops I didn't think that it would affect the carry status Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 4, 2005 Author Share Posted January 4, 2005 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? Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted January 4, 2005 Share Posted January 4, 2005 I dunno...I'm just a hacker Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted January 4, 2005 Share Posted January 4, 2005 Hi there! It just moves the highest bit into the carry. For example you can do lsr swchb to check the reset switch. Oops I didn't think that it would affect the carry status 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... Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 4, 2005 Author Share Posted January 4, 2005 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... 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 Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted January 4, 2005 Share Posted January 4, 2005 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? Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted January 4, 2005 Share Posted January 4, 2005 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 Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
Tom Posted January 4, 2005 Share Posted January 4, 2005 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 =) Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 5, 2005 Share Posted January 5, 2005 And what do other emus ? No, Manuel was just joking. Actually only PCAE has this (confirmed?) bug. Quote Link to comment Share on other sites More sharing options...
carlsson Posted January 7, 2005 Share Posted January 7, 2005 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... Quote Link to comment Share on other sites More sharing options...
carlsson Posted January 7, 2005 Share Posted January 7, 2005 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... Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 8, 2005 Author Share Posted January 8, 2005 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. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted January 8, 2005 Share Posted January 8, 2005 ...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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.