emulationmicroprocessors6502

How does the 6502 handle effective address overflow in indexed addressing modes?


What happens if the result of the addition performed in indexed addressing modes is greater than 0xFFFF? To be clear, I am referring not to the carry from the lower to the higher byte, but rather to the carry from the higher byte.

For example, for an instruction using absolute X-indexed addressing, what would be the result of calling it with an operand of 0xFFAA when the x-index register contains 0xFF? Would this overflow into 0x00AA? Would the result of 0x100A9 be truncated to 0x00A9? Would the processor freeze?

For some reason there is no information on this anywhere. This does not even seem to be mentioned in MOS' official programming guide for the 650X family.


Solution

  • The processor will not freeze.

    It wraps around. Exactly how it wraps around depends on the addressing mode, as pointed out by @JeremyP.

    The normal 16-bit addressing mode

    After 0xFFFF it wraps around to 0x0000.

    0xFFAA + 0x00FF will map to 0x00A9

    The explicit zero-page addressing mode

    If you are using the special zero-page addressing mode, i.e. which can only hold an 8-bit address, it wraps around within zero-page only, from 0xFF to 0x00.

    0xAA + 0xFF will map to 0xA9, i.e. to the 16-bit address 0x00A9.