Question

Reading the documentation on the 6502, and I havent been able to find this answered anywhere. It's possible to wrap when using relative addressing. But is it possible to wrap around both ends? I am guessing that is possible however unlikely though.

And when I mean both ends, I mean I know you can wrap from a high PC to a low PC. But could you also wrap from a low PC to a high PC?

Was it helpful?

Solution

Crossing a page boundary with a relative branch will incur an extra cycle, but it doesn't make any difference whether the page-crossing branch is a forward branch or a backwards branch.

You can try this out in Visual6502. Enter the program A9 00 F0 EC (LDA #00 / BEQ $FFF0) at address 0000, single-step through the code and see where it ends up after the BEQ. If you only trust real hardware you could easily verify this on something like a Nintendo Entertainment System.

Obviously to be able to reach page FF with a relative branch you'd have to be executing out of zeropage RAM, and you probably don't want to waste ZP RAM on code since it needs to fit your most frequently accessed data. So that would make this particular scenario unlikely.

OTHER TIPS

Yes, it works backwards, too. But many assemblers doesn't support that. When you try to put a branch operator at the beginning of zeropage addressing >$ff80 area, assemblers usually throws errors like "offset too large". But when you try placing the opcode with byte values like > 0002 f0 e0 you get the result beq $ffe4. I used 0002 as the first memory address available since I used a Commodore 64 to try it and $0001 is not usable for that machine. For other 6502 based machines, $0000 should be ok, too.

In a general way, you can perform your own address calculation using modulo arithmetic and then use the result for the absolute addressing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top