Beispiel #1
0
 def op(self, a, b):
     boolean = fn(self, a, b)
     if not boolean:
         # get the arguments from the next word
         _, n_a, n_b = as_opcode(self.RAM[self.registers["PC"]])
         # compute the length of the next word's values.
         length = self.values[n_a].consumes + self.values[n_b].consumes
         # jump ahead that many words.
         self.registers["PC"] += 1 + length
Beispiel #2
0
 def parse_instruction(self, word):
     o, a_code, b_code = as_opcode(word)
     # if this is a special opcode...
     if o == 0x00:
         # arguments are switched for the special opcodes
         a = self.values[b_code](self)
         name = self.special_opcodes[a_code]
         # return the name and the arguments
         return name, (a,)
     else:
         a = self.values[a_code](self)
         b = self.values[b_code](self)
         name = self.opcodes[o]
         # return the name of the operation and the arguments
         return name, (a, b)
Beispiel #3
0
 def parse_instruction(self, word, address=None):
     o, a_code, b_code = as_opcode(word)
     # if this is a special opcode...
     if o == 0x00:
         # arguments are switched for the special opcodes
         a = self.values[b_code](self)
         name = self.special_opcodes.get(a_code)
         if name == None:
             raise OpcodeError(o, address)
         # return the name and the arguments
         return name, (a,)
     else:
         a = self.values[a_code](self)
         b = self.values[b_code](self)
         name = self.opcodes.get(o)
         if name == None:
             raise OpcodeError(o, address)
         # return the name of the operation and the arguments
         return name, (a, b)
Beispiel #4
0
 def test_instructions(self):
     for code, (eo, ea, eb) in instructions.items():
         o, a, b = as_opcode(code)
         #print "expected: %x %x %x" % (eo, ea, eb)
         #print "got     : %x %x %x" % (o, a, b)
         self.assertEqual((eo, ea, eb), (o, a, b))