Пример #1
0
 def test_execute_register_to_register(self):
     mov = Mov('ax', 'ip')
     ctx = Context([None])
     ctx.registers.set(IP, 2)
     self.assertEqual(ctx.registers.get(AX).value, 0)
     mov.execute(ctx)
     self.assertEqual(ctx.registers.get(IP).value, 2)
Пример #2
0
 def test_execute_register_to_address(self):
     mov = Mov('[ax]', 'dx')
     ctx = Context([None])
     ctx.registers.set(AX, 2)
     ctx.registers.set(DX, 9)
     self.assertEqual(ctx.registers.get(DX).value, 9)
     mov.execute(ctx)
     self.assertEqual(ctx.heap.get(2)[0], 9)
Пример #3
0
 def test_execute_address_to_register(self):
     mov = Mov('ax', '[ip]')
     ctx = Context([None])
     ctx.registers.set(IP, 2)
     ctx.heap.set(2, 9)
     self.assertEqual(ctx.registers.get(AX).value, 0)
     mov.execute(ctx)
     self.assertEqual(ctx.registers.get(AX).value, 9)
Пример #4
0
 def test_parse_03(self):
     self.assertRaises(SyntaxError, lambda: Mov.parse(['ax,', 'bx', 'ip']))
Пример #5
0
 def test_parse_02(self):
     mov = Mov.parse(['ax,', 'bx'])
     self.assertEqual(mov.source, 'bx')
     self.assertEqual(mov.dest, 'ax')
Пример #6
0
 def test_parse_01(self):
     mov = Mov.parse(['ax', 'bx'])
     self.assertIsInstance(mov, Mov)
Пример #7
0
 def test_execute_constant_to_register(self):
     mov = Mov('ax', '2')
     ctx = Context([None])
     self.assertEqual(ctx.registers.get(AX).value, 0)
     mov.execute(ctx)
     self.assertEqual(ctx.registers.get(AX).value, 2)