View Source Chip8.Interpreter.Instruction behaviour (chip8 v1.1.0)
Module to interact with interpreter's opcodes.
The interpreter's instruction set includes 36 instructions, that allow programs to perform operations of arithmetic, control flow, data manipulation, graphics, and logical.
All instructions are 2 bytes
long and are stored in a big-endian format.
In memory, the interpreter assumes that all instructions should start at an
even address, and needs to be taken into account when adding
sprite data, see Chip8.Interpreter.Display.Sprite
for more information.
instruction-definition
Instruction Definition
Instructions are grouped in modules that represent their operation and share the same mnemonic, making different opcodes as simple variants. Inside each module, there is a table describing all variants supported by the module, each variant specifies its opcode and the effects applied into the interpreter once it is invoked.
Since each variant supports a different type of value as operands (i.e. arguments), the notation below is used to compactly describe the use of each part inside the opcode:
nnn
oraddress
- A 12-bit integer value, representing an memory addressn
ornibble
- A 4-bit integer value, representing a literal numberkk
orbyte
- An 8-bit integer value, representing a literal numberx
orVx
- A 4-bit integer value, representing one of the 16 variable registersy
orVy
- A 4-bit integer value, representing one of the 16 variable registers
decode
Decode
#
When decoding an instruction, the given 2 bytes
list is transformed into a
Chip8.Interpreter.Instruction.t/0
, containing the module that supports the
given opcode as one of its variants and the arguments, that was also
parsed into its equivalent struct i.e. an nnn
address is transformed into a
Chip8.Interpreter.Instruction.Argument.Address.t/0
.
In case an unknown segment of bytes is given, an error is returned.
Link to this section Summary
Link to this section Types
@type arguments() :: {} | {Chip8.Interpreter.Instruction.Argument.Address.t()} | {Chip8.Interpreter.Instruction.Argument.Register.t()} | {Chip8.Interpreter.Instruction.Argument.Register.t(), Chip8.Interpreter.Instruction.Argument.Address.t()} | {Chip8.Interpreter.Instruction.Argument.Register.t(), Chip8.Interpreter.Instruction.Argument.Byte.t()} | {Chip8.Interpreter.Instruction.Argument.Register.t(), Chip8.Interpreter.Instruction.Argument.Register.t()} | {Chip8.Interpreter.Instruction.Argument.Register.t(), Chip8.Interpreter.Instruction.Argument.Register.t(), Chip8.Interpreter.Instruction.Argument.Nibble.t()}
Link to this section Callbacks
@callback execute(Chip8.Interpreter.t(), arguments()) :: Chip8.Interpreter.t()
Link to this section Functions
@spec byte_size() :: integer()
@spec decode(Chip8.Interpreter.Memory.data()) :: {:ok, t()} | {:error, atom()}
@spec execute(t(), Chip8.Interpreter.t()) :: Chip8.Interpreter.t()