Instruction Modes
modesNearly all xyw instructions support different modes, that change their behavior slightly to support word (2-byte) values and work with registers.
Modes are encoded with an instruction opcode by applying bit mask on the last three bytes, like this:
11001100 => $CC
│││└└└└└ base opcode ($0C)
││└ mode w not set
│└ mode y set ($40)
└ mode x set ($80)
In this case, the final opcode will be $CC, which is an ADD instruction ($0C) with modes x and y both set (ADDxy).
=== Modes x and y (register modes)
If mode x or y are set, the corresponding 8-bit register will be used, typically instead of popping an argument from the stack (like for ADDx or SUBy), and in some cases as a "destination" for the result of an instruction (such as for POPx or POPy).
If both modes are specified, both registers will be used in some way, typically as two arguments for an instruction.
If a register mode is specified in conjunction with w mode, the corresponding word-size register will be used (xw or yw).
=== Mode w (word mode)
If mode w is specified, the instruction will operate in words (16-bit) values instead of bytes.
=== Mode application rules
every instruction that takes at least one parameter supports word mode.
Both register modes are supported only for instructions that take two arguments of the same size.
Only one register mode is supported for instructions that take two parameters but one of them has a fixed size (byte or word).
unary operations support only one register mode and if specified they modify its value in place, without pushing the result to the stack.