Sakrac / x65

6502 Macro Assembler in a single c++ file using the struse single file text parsing library. Supports most syntaxes.
MIT License
38 stars 7 forks source link

65816 BRK opcode, ignores argument #9

Open dwsJason opened 4 years ago

dwsJason commented 4 years ago

$0010 00 brk 7 brk $22

This should assemble to 00 22, at least on 65816 code

Sakrac commented 4 years ago

Is this a different interpretation of brk than http://6502.org/tutorials/65c816opcodes.html#6.3.1 ? Or am I missing something?

dwsJason commented 4 years ago

That tutorial is wrong. While the BRK itself, is a single byte, and 00. When the interrupt handler returns from the BRK, the PC is incremented 2, not 1. In the Apple 2 monitor ROM, all disassembly show the BRK as a 2 byte opcode, because of this behavior. Accross the entire 6502 family, BRK should be treated as a 2 byte instruction.

Sakrac commented 4 years ago

I checked and you're right, had no idea! I think the expectation of writing brk in assembly is that you get a single byte instruction since that is what the manual says but writing brk #$xx as a two byte instruction makes total sense now.

Sakrac commented 4 years ago

brk immediate mode added.