Exemplo n.º 1
0
 def test_not(self):
     mc = Microcontroller()
     self.assertEqual(0, mc.acc)
     mc.execute("not")
     self.assertEqual(100, mc.acc)
     mc.register('acc').write('-999')
     mc.execute("not")
     self.assertEqual(0, mc.acc)
Exemplo n.º 2
0
 def test_acc_register(self):
     mc1 = Microcontroller(name='mc1', gpio=1)
     acc = mc1.register('acc')
     self.assertEqual(0, acc.read())
     self.assertEqual(0, mc1.acc)
     mc1.execute('add 1')
     self.assertEqual(1, acc.read())
     self.assertEqual(1, mc1.acc)
Exemplo n.º 3
0
 def test_mov_to_null(self):
     c = """
       mov 100 null
       mov 50 acc
       mov null acc
     """
     mc = Microcontroller()
     mc.execute(c)
     self.assertEqual(0, mc.acc)
Exemplo n.º 4
0
 def test_add_and_sub(self):
     mc1 = Microcontroller(name="mc1", gpio=1)
     mc1.execute('add 1')
     self.assertEqual(1, mc1.acc)
     mc1.execute('add 1')
     self.assertEqual(2, mc1.acc)
     mc1.execute('sub 1')
     self.assertEqual(1, mc1.acc)
     mc1.execute('#sub 1')
     self.assertEqual(1, mc1.acc)
     with self.assertRaises(x.CommandException):
         mc1.execute('lawl')
Exemplo n.º 5
0
 def test_tgt(self):
     code = """
       tgt acc 2
     + mov 3 acc
     - mov 1 acc
     """
     mc = Microcontroller()
     mc.execute(code)
     self.assertEqual(1, mc.acc)
     mc.register('acc').write(2)
     mc.execute(code)
     self.assertEqual(1, mc.acc)
Exemplo n.º 6
0
 def test_mov(self):
     mc1 = Microcontroller(name='mc1', dats=1)
     acc = mc1.register('acc')
     dat = mc1.register('dat')
     acc.write(42)
     mc1.execute('mov acc dat')
     self.assertEqual(42, dat.read())
     self.assertEqual(42, acc.read())
     dat.write(12)
     mc1.execute('mov dat acc')
     self.assertEqual(12, acc.read())
     self.assertEqual(12, dat.read())
Exemplo n.º 7
0
 def test_teq(self):
     code = """
       teq acc 2
     + mov 1 acc
     - mov 3 acc
     """
     mc = Microcontroller(name='mc1')
     mc.execute(code)
     self.assertEqual(3, mc.acc)
     mc.register('acc').write(2)
     self.assertEqual(2, mc.acc)
     mc.execute(code)
     self.assertEqual(1, mc.acc)
Exemplo n.º 8
0
    def test_jump(self):
        code = """
        a:add 1
          teq acc 5
        - jmp a
        """
        mc = Microcontroller()
        mc.execute(code)
        self.assertEqual(5, mc.acc)

        code = """
        a:
          add 1
          teq acc 5
        - jmp a
        """
        mc = Microcontroller()
        mc.execute(code)
        self.assertEqual(5, mc.acc)
Exemplo n.º 9
0
 def test_dst(self):
     mc = Microcontroller()
     mc.register('acc').write(567)
     mc.execute('dst 0 9')
     self.assertEqual(569, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dst 1 9')
     self.assertEqual(597, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dst 2 9')
     self.assertEqual(967, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dst 3 9')
     self.assertEqual(0, mc.acc)
Exemplo n.º 10
0
 def test_dgt(self):
     mc = Microcontroller()
     mc.register('acc').write(567)
     mc.execute('dgt 0')
     self.assertEqual(7, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dgt 1')
     self.assertEqual(6, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dgt 2')
     self.assertEqual(5, mc.acc)
     mc.register('acc').write(567)
     mc.execute('dgt 3')
     self.assertEqual(0, mc.acc)
Exemplo n.º 11
0
 def test_mov_to_port(self):
     c1 = """
       mov 10 p0
     """
     c2 = """
       add p1
     """
     mc1 = Microcontroller(gpio=1)
     mc2 = Microcontroller(gpio=2)
     mc1.p0.link(mc2.p1)
     mc1.execute(c1)
     mc2.execute(c2)
     self.assertEqual(10, mc2.acc)
     mc2.execute(c2)
     self.assertEqual(20, mc2.acc)
Exemplo n.º 12
0
 def test_nop(self):
     mc = Microcontroller()
     mc.execute("nop")
Exemplo n.º 13
0
 def test_mul(self):
     mc = Microcontroller()
     mc.register('acc').write(2)
     mc.execute('mul 5')
     self.assertEqual(10, mc.acc)
Exemplo n.º 14
0
 def test_execute_bad_register(self):
     mc = Microcontroller(name='mc1', dats=0)
     with self.assertRaises(x.RegisterException):
         mc.execute('mov 1 dat')