Esempio n. 1
0
def setUpInstruction(op_code, cfg, data_type=VAL_BOOL):
    instruction = Instruction(op_code)
    instruction.cfg_mask = cfg
    instruction.rd = 1
    instruction.ra = 2
    instruction.rb = 3
    instruction.imma = 122
    instruction.immb = 123
    instruction.address = 124
    instruction.type = data_type
    return instruction
Esempio n. 2
0
 def test_decode_next(self):
     # add r3 r1 r2
     expected_instruction_add = Instruction(OP_ADD,
                                            rd=3,
                                            ra=1,
                                            rb=2,
                                            cfg_mask=CFG_RR)
     self.assertEqual(expected_instruction_add, self.decoder.decode_next())
     self.assertEqual(1, self.decoder.next_instruction_index)
     # sub r3 r1 122
     expected_instruction_sub = Instruction(OP_SUB,
                                            rd=3,
                                            ra=1,
                                            immb=122,
                                            cfg_mask=CFG_RI)
     self.assertEqual(expected_instruction_sub, self.decoder.decode_next())
     self.assertEqual(2, self.decoder.next_instruction_index)
Esempio n. 3
0
 def test_decode_mov_imm(self):
     # mov r3 234
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_IMM,
                                        rd=3,
                                        imma=234)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[7]))
Esempio n. 4
0
 def test_decode_mov_reg(self):
     # mov r3 r1
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_REG,
                                        rd=3,
                                        ra=1)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[6]))
Esempio n. 5
0
 def test_decode_store_state_raa(self):
     # storestate r3 r1
     expected_instruction = Instruction(OP_STORE,
                                        cfg_mask=STORE_RAA,
                                        rd=3,
                                        ra=1,
                                        inst_type=VAL_STATE)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[22]))
Esempio n. 6
0
 def test_decode_store_bool_adr(self):
     # storebool r3 234
     expected_instruction = Instruction(OP_STORE,
                                        cfg_mask=STORE_ADR,
                                        rd=3,
                                        address=234,
                                        inst_type=VAL_BOOL)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[17]))
Esempio n. 7
0
 def test_decode_load_state_adr(self):
     # loadstate r3 234
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_ADR,
                                        rd=3,
                                        address=234,
                                        inst_type=VAL_STATE)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[15]))
Esempio n. 8
0
 def test_decode_load_state_raa(self):
     # loadstate r3 r1
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_RAA,
                                        rd=3,
                                        ra=1,
                                        inst_type=VAL_STATE)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[14]))
Esempio n. 9
0
 def test_decode_load_int_raa(self):
     # loadint r3 r1
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_RAA,
                                        rd=3,
                                        ra=1,
                                        inst_type=VAL_INT)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[12]))
Esempio n. 10
0
 def test_decode_load_bool_adr(self):
     # loadbool r3 234
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_ADR,
                                        rd=3,
                                        address=234,
                                        inst_type=VAL_BOOL)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[9]))
Esempio n. 11
0
 def test_decode_load_bool_raa(self):
     # loadbool r3 r1
     expected_instruction = Instruction(OP_LOAD,
                                        cfg_mask=LOAD_RAA,
                                        rd=3,
                                        ra=1,
                                        inst_type=VAL_BOOL)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[8]))
Esempio n. 12
0
 def test_decode_store_state_adr(self):
     # storestate r3 234
     expected_instruction = Instruction(OP_STORE,
                                        cfg_mask=STORE_ADR,
                                        rd=3,
                                        address=234,
                                        inst_type=VAL_STATE)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[23]))
Esempio n. 13
0
 def test_decode_store_bool_raa(self):
     # storebool r3 r1
     expected_instruction = Instruction(OP_STORE,
                                        cfg_mask=STORE_RAA,
                                        rd=3,
                                        ra=1,
                                        inst_type=VAL_BOOL)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[16]))
Esempio n. 14
0
 def test_decode_bin_II(self):
     # eq r3 123 124
     expected_instruction = Instruction(OP_EQ,
                                        rd=3,
                                        imma=123,
                                        immb=124,
                                        cfg_mask=CFG_II)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[3]))
Esempio n. 15
0
 def test_decode_bin_IR(self):
     # mod r3 122 r2
     expected_instruction = Instruction(OP_MOD,
                                        rd=3,
                                        imma=122,
                                        rb=2,
                                        cfg_mask=CFG_IR)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[2]))
Esempio n. 16
0
 def test_decode_bin_RI(self):
     # sub r3 r1 122
     expected_instruction = Instruction(OP_SUB,
                                        rd=3,
                                        ra=1,
                                        immb=122,
                                        cfg_mask=CFG_RI)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[1]))
Esempio n. 17
0
 def test_decode_bin_RR(self):
     # add r3 r1 r2
     expected_instruction = Instruction(OP_ADD,
                                        rd=3,
                                        ra=1,
                                        rb=2,
                                        cfg_mask=CFG_RR)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[0]))
Esempio n. 18
0
 def test_decode_not(self):
     # not r3 r1
     expected_instruction = Instruction(OP_NOT, rd=3, ra=1)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[4]))
Esempio n. 19
0
 def test_decode_jmp(self):
     # jmp r3 234
     expected_instruction = Instruction(OP_JMP, rd=3, address=234)
     self.assertEqual(expected_instruction,
                      self.decoder.decode(self.bit_instructions[5]))