2 trit_integer
= {"i": -1, "0":0, "1":1}
4 def Decoder(tritstream
):
5 """ Decode a single instruction.
6 tristream: stream of trits will only process the first 3 trits.
7 return: dictionary containing the operation
9 inst
= {"op":trit_integer
[tritstream
[0]]}
12 if inst
["op"] == -1 or inst
["op"] == 1:
13 inst
["src1"] = trit_integer
[tritstream
[1]]
14 inst
["src2"] = trit_integer
[tritstream
[2]]
19 inst
["src1"] = trit_integer
[tritstream
[1]]
20 inst
["src2"] = trit_integer
[tritstream
[2]]
21 inst
["immed"] = 3*inst
["src1"] + inst
["src2"]
25 def Execute(memory
, registers
, pc
):
26 """ Execute one instruction.
27 memory: were decoded instructions are stored
28 registers: contains registers and their values
32 op
= (memory
[pc
])["op"]
36 src1
= (memory
[pc
])["src1"]
37 src2
= (memory
[pc
])["src1"]
38 if (registers
[src1
] - registers
[src2
]) == 0:
44 registers
[1] = (memory
[pc
])["immed"]
47 if registers
["S"] == 0:
48 op
= (memory
[pc
])["src1"]
50 op
= (memory
[pc
])["src2"]