def test_subroutine_call_and_return():
    cpu = Cpu([])
    cpu.instruction_pointer = 10

    CallSubroutine(42).execute(cpu)

    assert cpu.instruction_pointer == 42

    Return().execute(cpu)

    assert cpu.instruction_pointer == 10
 def execute(self, cpu: Cpu):
     if cpu.registers[self.register_a] > cpu.registers[self.register_b]:
         cpu.instruction_pointer = self.instruction_index
Beispiel #3
0
 def execute(self, cpu: Cpu):
     cpu.stack.append(cpu.instruction_pointer)
     cpu.instruction_pointer = self.instruction_index
Beispiel #4
0
 def execute(self, cpu: Cpu):
     return_address = cpu.stack.pop()
     cpu.instruction_pointer = return_address
Beispiel #5
0
 def execute(self, cpu: Cpu):
     cpu.instruction_pointer = self.instruction_index