XCE
Exchange Carry & Emulation Bits
This instruction is the only means to shift a 65802 or 65812 processor between 6502 emulation mode and full 16-bit native mode.
Switch to native 16-bit mode
To switch into native mode, clear the carry bit then invoke XCE
1.goNative
2 CLC ; Clear Carry to indicate native mode
3 XCE ; Processor will be in 16-bit native mode once this completes
4 RTS ; Carry will now set if we were originally in emulation or clear if already native.
Once XCE has completed and the processor is in native mode, the following would have occurred.
- bit 5 of the flags stops being the b break flag. It's now the x mode select flag
- bit 6 is now the m memory mode flag (it's unused in 6502 emulation mode)
- Both x & m are set to 1
Switch to 6502 emulation mode
To switch into 6502 emulation mode, set the carry bit then invoke XCE
1.goEmulation
2 SEC ; Set Carry to indicate native mode
3 XCE ; Processor will be in 16-bit native mode once this completes
4 RTS ; Carry will now set if we were already in emulation or clear if we were originally native.
Once XCE has completed and the processor is in 6502 emulation mode, the following would have occurred.
- The x & m flags are lost from the status register.
- bit 6 is unavailable as it's unused in 6502 emulation mode
- The accumulator is forced into 8-bit's, the high 8 bits are in the hidden B accumulator
- The index registers are forced into 8-bits. The high 8-bits are lost.
- The stack pointer is forced into page 1, losing the high byte of the address.
Flags Affected
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
m | Set to 1 when switching to native mode, otherwise clear | ||||||||
c | Takes emulations previous value |
Instructions
Syntax | Opcode | Available on: | # of | # of | Addressing Mode | ||
---|---|---|---|---|---|---|---|
(hex) | 6502 | 65C02 | 65816 | bytes | cycles | ||
XCE | FB | x | 1 | 2 | Implied |
Last modified November 5, 2021: Add instruction categories (6b74ff9)