def __init__(self, op: Callable[[bool, bool], bool], args: List[Union[str, int]]): self.operator = op self.register = args[0] if isinstance(args[1], str): self.argument = args[1] self.literal = False else: self.argument = Memory.MEMORY_IMPL(Memory.REGISTER_WIDTH, False) self.argument.set_value(args[1]) self.literal = True
def test_bitwise_ops_stress(self): for o in op.BitwiseOperation.OPS.values(): for i in range(0, ITERATIONS): v1 = random.randint(0, MAX) self.proc.memory.set_register('s1', v1) self.proc.set_carry(False) operation = op.BitwiseOperation(o, ['s1']) operation.exec(self.proc) r = Memory.MEMORY_IMPL(Memory.REGISTER_WIDTH) r.set_value(v1) r.values = o(operation, r) self.assertEqual(self.proc.memory.fetch_register('s1'), r.value)
def jump_at(self): upper = self.proc.memory.REGISTERS[self.address_parts[0]].values lower = self.proc.memory.REGISTERS[self.address_parts[1]].values # 12 bit JUMP@ instruction complete_row = Memory.MEMORY_IMPL(12, False) # lower 4 bits of upper segment complete_row.values = upper[3:7] # all of the lower segment complete_row.values.extend(lower) # jump to the address value self.address = complete_row.value self.jump()
def __init__(self, op: Callable[[List[bool], List[bool]], List[bool]], args: List[Union[str, int]]): self.operator = op self.register = args[0] if isinstance(args[1], str): self.argument = args[1] self.literal = False else: self.argument = Memory.MEMORY_IMPL(Memory.REGISTER_WIDTH, False) self.argument.set_value(args[1]) self.literal = True self.proc = None # type: Processor self.zero_bits = [False for _ in range(Memory.REGISTER_WIDTH) ] # type: List[bool]
def __init__(self, isr_addr=0x3FF): self._mem = Memory() self.manager = ProgramManager(isr_addr=isr_addr) self._last_instruction = 0 self._instructions = {} # type Dict[hex, Instruction] self.p_carry = False # type: bool self.p_zero = False # type: bool self.p_interrupt_ack = False # type: bool self.p_out_port = 0x00 # type: hex self.p_port_id = 0x00 # type: hex self._interrupt_enabled = False # type: bool self._interrupt = False # type: bool self._preserved_carry = False # type: bool self._preserved_zero = False # type: bool self._in_port = 0x00 # type: hex self.external = Processor.ExternalInterface(self)
def setUp(self): self.proc = Processor() self.r = Memory.MEMORY_IMPL(Memory.REGISTER_WIDTH)
def setUp(self): self.mem = Memory()
class MemoryTests(unittest.TestCase): def setUp(self): self.mem = Memory() def test_fetch_register(self): self.assertEqual(self.mem.fetch_register('s0'), 0) def test_set_fetch_register(self): self.assertEqual(self.mem.fetch_register('s1'), 0) self.mem.set_register('s1', 62) self.assertEqual(self.mem.fetch_register('s1'), 62) self.mem.set_register('s1', 0) self.assertEqual(self.mem.fetch_register('s1'), 0) self.mem.set_register('s2', MAX) self.assertEqual(self.mem.fetch_register('s2'), MAX) self.mem.set_register('s3', MAX) self.assertEqual(self.mem.fetch_register('s3'), MAX) def test_set_fetch_register_stress(self): reg = 's%0.1x' % random.randint(0x0, 0xF) for _ in range(0, ITERATIONS): val = random.randint(0, MAX) self.mem.set_register(reg, val) self.assertEqual(self.mem.fetch_register(reg), val) val = random.randint(-32768, 32767) c_val = make_positive(val) self.mem.set_register(reg, c_val) # check properly converted to 2s comp self.assertEqual(self.mem.fetch_register(reg), c_val) def test_register_edge(self): with self.assertRaises(KeyError): self.mem.set_register("s10", 0) self.mem.set_register("s1", MAX + 1) self.assertEqual(self.mem.fetch_register('s1'), 0) self.mem.set_register("s1", MAX + 2) self.assertEqual(self.mem.fetch_register('s1'), 1) self.mem.set_register("s1", -1) self.assertEqual(self.mem.fetch_register('s1'), MAX) self.mem.set_register("s1", MIN + 1) self.assertEqual(self.mem.fetch_register('s1'), -MIN + 1) self.mem.set_register("s1", MIN) self.assertEqual(self.mem.fetch_register('s1'), -MIN) self.mem.set_register("s1", MIN - 1) self.assertEqual(self.mem.fetch_register('s1'), 0)