2 # vim: set fileencoding=utf8
4 import base_converter
, Trits
10 # decode trit instrucion code
13 # decode string instruction
16 assert "ICode __init__, unable to parse:", s
18 def decode_code(self
, s
):
22 --------------------------------------------------------
23 | type(2) | opcode(13) | rs(3) | rt(3) | rd(3) | sa(3) |
24 --------------------------------------------------------
26 --------------------------------------------------------
27 | type(2) | opcode(5) | rs(3) | rt(3) | immediate(14) |
28 --------------------------------------------------------
30 --------------------------------------------------------
31 | type(2) | opcode(4) | rs(3) | label0(9) | label(9) |
32 --------------------------------------------------------
34 --------------------------------------------------------
35 | type(2) | opcode(4) | address(21) |
36 --------------------------------------------------------
39 type = int(base_convert(s
[0:2], -3, 10))
42 self
.alu_op
= int(base_convert(s
[2:15], -3, 10))
43 self
.src1
= int(base_convert(s
[15:18], -3, 10))
44 self
.src2
= int(base_convert(s
[18:21], -3, 10))
45 self
.dest
= int(base_convert(s
[21:24], -3, 10))
46 self
.imdt1
= int(base_convert(s
[24:27], -3, 10))
52 self
.alu_op
= int(base_convert(s
[2:7], -3, 10))
53 self
.src1
= int(base_convert(s
[7:10], -3, 10))
54 self
.src2
= int(base_convert(s
[10:13], -3, 10))
55 self
.imdt1
= int(base_convert(s
[13:27], -3, 10))
62 self
.alu_op
= int(base_convert(s
[2:6], -3, 10))
63 self
.src1
= int(base_convert(s
[6:9], -3, 10))
64 self
.imdt1
= int(base_convert(s
[9:18], -3, 10))
65 self
.imdt2
= int(base_convert(s
[18:27], -3, 10))
72 self
.alu_op
= int(base_convert(s
[2:6], -3, 10))
73 self
.imdt1
= int(base_convert(s
[6:27], -3, 10))
82 raise DecodeError("invalid type code = %s" % (type, ))