Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instruction Set
// 0nnn - SYS addr
// 00E0 - CLS
// 00EE - RET
// 1nnn - JP addr
// 2nnn - CALL addr
// 3xkk - SE Vx, byte
const INSTRUCTION_SET = [
{
name: 'SYS',
mask: 0xf000,
pattern: 0x0000,
arguments: [ { mask: 0x0fff, shift: 0, type: 'Address' } ],
},
{
name: 'CLS',
mask: 0x00f0,
pattern: 0x00e0,
arguments: [],
},
{
name: 'RET',
mask: 0x00ff,
pattern: 0x00ee,
arguments: [],
},
{
name: 'JP',
mask: 0xf000,
pattern: 0x1000,
arguments: [ { mask: 0x0fff, shift: 0, type: 'Address' } ],
},
{
name: 'CALL',
mask: 0xf000,
pattern: 0x2000,
arguments: [ { mask: 0x0fff, shift: 0, type: 'Address' } ],
},
{
name: 'SE',
mask: 0xf000,
pattern: 0x3000,
arguments: [
{ mask: 0x0f00, shift: 8, type: 'Register' },
{ mask: 0x00ff, shift: 0, type: 'Constant' },
],
},
]
function findInstruction(opcode) {
let match = INSTRUCTION_SET.filter(
instruction => (opcode & instruction.mask) === instruction.pattern
)
return match[0]
}
let opcode = 0x1fff
console.log(findInstruction(opcode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.