예제 #1
0
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
예제 #3
0
 def execute(self, cpu: Cpu):
     cpu.stack.append(cpu.instruction_pointer)
     cpu.instruction_pointer = self.instruction_index
예제 #4
0
 def execute(self, cpu: Cpu):
     return_address = cpu.stack.pop()
     cpu.instruction_pointer = return_address
예제 #5
0
 def execute(self, cpu: Cpu):
     cpu.instruction_pointer = self.instruction_index