def test_signed_int(self):
     """lib.functions.binary extends sign correctly"""
     a = bin(-4, 8)[2:]
     b = bin(4, 8)[2:]
     self.assertEquals('11111100', a)
     self.assertEquals('00000100', b)
     c = int(a, 2, signed=True)
     d = int(b, 2, signed=True)
     self.assertEquals(-4, c)
     self.assertEquals(4, d)
Example #2
0
 def test_break_point(self):
     """Adds a break point and checks for SigTrap."""
     i=self.assembler.read_lines(['addi $s1, $zero, 255\n',
                                    'addi $s2, $zero, 1023\n',
                                    'slt  $s0, $s1, $s2'])
     i=self.assembler.convert(i)
     self.memory.load_text(i)
     self.cpu.add_break_point(int('0x40000c', 16))
     cycles = 100
     with self.assertRaises(SigTrap):
         for i in range(cycles):
             self.cpu.cycle()
     # Shouldn't get anywhere near 100 cycles.
     self.assertEquals(True, (i < 50))
     # We should have fetched the slt instruction.
     self.assertEquals("00000010001100101000000000101010",
                       bin(self.cpu.get_pipeline()[0], 32)[2:])