Sakrac / x65

6502 Macro Assembler in a single c++ file using the struse single file text parsing library. Supports most syntaxes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

65816 BRK opcode, ignores argument

dwsJason opened this issue · comments

$0010 00 brk 7 brk $22

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

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

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.

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.

brk immediate mode added.