22 lines
568 B
Python
22 lines
568 B
Python
from instruction_table import untabulate_instructions_sh2
|
|
|
|
instruction_table = untabulate_instructions_sh2()
|
|
|
|
def match_instruction(n, ins):
|
|
return (n & ins.code.mask_bits) == ins.code.code_bits
|
|
|
|
def decode_instruction(n):
|
|
global instruction_table
|
|
|
|
for ins in instruction_table:
|
|
if match_instruction(n, ins):
|
|
return ins
|
|
return None
|
|
|
|
def decode_variables(n, ins):
|
|
operands = ins.code.operands
|
|
return [
|
|
(n >> operands[variable].lsb) & ((1 << operands[variable].length) - 1)
|
|
for variable in ins.variables
|
|
]
|