Ejemplo n.º 1
0
 def get_instruction(self, location=None):
     state = State(self, location)
     # unpack the opcode, a, and b
     op, b, a = as_instruction(next(state.ram_iter))
     # get the mnemonic and the method corresponding to it.
     if op == 0:
         mnemonic = self.special_operations.get(b)
         if mnemonic is None:
             raise OpcodeError(b, location)
         a_value = self.values[a](state, True)
         arguments = (a_value,)
         state.dis = "{0} {1}".format(mnemonic, a_value.dis)
     else:
         mnemonic = self.operations.get(op)
         if mnemonic is None:
             raise OpcodeError(op, location)
         a_value = self.values[a](state, True)
         b_value = self.values[b](state, False)
         arguments = (b_value, a_value)
         state.dis = "{0} {1}, {2}".format(mnemonic, b_value.dis,
                 a_value.dis)
     method = getattr(self, mnemonic)
     # run the method and decide what changes to do.
     return method, arguments, state
Ejemplo n.º 2
0
 def is_conditional(self, instruction):
     o, b, a = as_instruction(instruction)
     name = self.operations.get(o)
     return name is not None and name.startswith("if")
Ejemplo n.º 3
0
 def test_instructions(self):
     for code, (eo, eb, ea) in instructions.items():
         o, b, a = as_instruction(code)
         #print "expected: %x %x %x" % (eo, ea, eb)
         #print "got     : %x %x %x" % (o, a, b)
         self.assertEqual((eo, eb, ea), (o, b, a))