Esempio n. 1
0
    def run(self, machine):
        if (Flag.SF in machine.flags) == (Flag.OF in machine.flags):
            return MachineUpdate()

        return MachineUpdate(
            registers={
                Register.pc: machine.registers[self.value_register],
            })
Esempio n. 2
0
    def run(self, machine):
        if Flag.ZF not in machine.flags:
            return MachineUpdate()

        return MachineUpdate(
            registers={
                Register.pc: machine.registers[self.value_register],
            })
Esempio n. 3
0
    def run(self, machine):
        if Flag.ZF not in machine.flags:
            return MachineUpdate()

        current = machine.registers[Register.pc].int_value()
        offset = machine.registers[self.value_register].int_value()
        updated_pc = Word.from_int(current + offset + self.size)

        return MachineUpdate(registers={
            Register.pc: updated_pc,
        })
Esempio n. 4
0
    def run(self, machine):
        if (Flag.SF in machine.flags) == (Flag.OF in machine.flags):
            return MachineUpdate()

        current = machine.registers[Register.pc].int_value()
        offset = self.value_word.int_value()
        updated_pc = Word.from_int(current + offset + self.size)

        return MachineUpdate(registers={
            Register.pc: updated_pc,
        })
Esempio n. 5
0
 def run(self, machine):
     dest = machine.registers[Register.sp]
     return MachineUpdate(
         memory={dest: machine.registers[self.value_register]},
         registers={
             Register.sp: machine.registers[Register.sp].incremented(-4)
         })
Esempio n. 6
0
    def run(self, machine):
        pop_address = machine.registers[Register.sp].incremented(4)
        payload = machine.memory.read_word(pop_address.int_value())

        return MachineUpdate(registers={
            self.value_register: payload,
            Register.sp: pop_address
        })
Esempio n. 7
0
    def run(self, machine):
        updated_sp_address = machine.registers[Register.sp].incremented(4)
        popped_pc = machine.memory.read_word(updated_sp_address.int_value())

        return MachineUpdate(registers={
            Register.pc: popped_pc,
            Register.sp: updated_sp_address
        })
Esempio n. 8
0
    def run(self, machine):
        current = machine.registers[Register.pc].int_value()
        offset = machine.registers[self.value_register].int_value()

        return MachineUpdate(
            registers={
                Register.pc: Word.from_int(current + offset + self.size),
            })
Esempio n. 9
0
    def run(self, machine):
        result, flags = subtract_word(machine.registers[self.dest_register],
                                      machine.registers[self.source_register])

        return MachineUpdate(registers={
            self.dest_register: result,
        },
                             flags=flags)
Esempio n. 10
0
    def run(self, machine):
        return_pointer = machine.registers[Register.pc].incremented(self.size)
        updated_pc = self.value_word.incremented(13)  # todo: spec error

        return MachineUpdate(
            memory={machine.registers[Register.sp]: return_pointer},
            registers={
                Register.pc: updated_pc,
                Register.sp: machine.registers[Register.sp].incremented(-4)
            })
Esempio n. 11
0
    def run(self, machine):
        if machine.stdin:
            user_int = machine.stdin.pop(0)
        else:
            user_input = input()
            user_int = ord(user_input[0])

        user_byte = Byte(user_int)

        return MachineUpdate(
            memory={machine.registers[self.value_register]: user_byte}, )
Esempio n. 12
0
    def run(self, machine):
        return_pointer = machine.registers[Register.pc].incremented(self.size)
        increment_amount = machine.registers[self.value_register]

        return MachineUpdate(
            memory={machine.registers[Register.sp]: return_pointer},
            registers={
                Register.pc:
                machine.registers[Register.pc].incremented(increment_amount),
                Register.sp:
                machine.registers[Register.sp].incremented(-4)
            })
Esempio n. 13
0
 def run(self, machine):
     payload = machine.registers[self.source_register]
     return MachineUpdate(registers={self.dest_register: payload})
Esempio n. 14
0
    def run(self, machine):
        char = machine.registers[self.value_register].low_byte()

        return MachineUpdate(stdout=char)
Esempio n. 15
0
    def run(self, machine):
        char = self.value_word.low_byte()

        return MachineUpdate(stdout=char)
Esempio n. 16
0
    def run(self, machine):
        result, _ = bitwise_or(machine.registers[self.dest_register],
                               machine.registers[self.source_register])

        return MachineUpdate(registers={self.dest_register: result})
Esempio n. 17
0
 def run(self, machine):
     return MachineUpdate(registers={Register.pc: self.value_word})
Esempio n. 18
0
 def run(self, machine):
     return MachineUpdate(
         registers={
             Register.pc: machine.registers[self.value_register],
         })
Esempio n. 19
0
    def run(self, machine):
        _, flags = bitwise_and(machine.registers[self.dest_register],
                               machine.registers[self.source_register])

        return MachineUpdate(registers={self.dest_register: result},
                             flags=flags)
Esempio n. 20
0
    def run(self, machine):
        result = bitwise_not(machine.registers[self.value_register])

        return MachineUpdate(registers={self.value_register: result})
Esempio n. 21
0
 def run(self, machine):
     result = machine.registers[self.dest_register].low_byte()
     return MachineUpdate(
         memory={machine.registers[self.source_register]: result})
Esempio n. 22
0
 def run(self, machine):
     result = machine.registers[self.dest_register]
     return MachineUpdate(memory={self.source_word: result})
Esempio n. 23
0
    def run(self, machine):
        result, flags = bitwise_xor(machine.registers[self.dest_register],
                                    self.source_word)

        return MachineUpdate(registers={self.dest_register: result},
                             flags=flags)
Esempio n. 24
0
    def run(self, machine):
        _, flags = bitwise_and(machine.registers[self.dest_register],
                               self.source_word)

        return MachineUpdate(flags=flags)
Esempio n. 25
0
    def run(self, machine):
        if Flag.ZF not in machine.flags:
            return MachineUpdate()

        return MachineUpdate(
            registers={Register.pc: self.value_word.incremented(13)})
Esempio n. 26
0
 def run(self, machine):
     return MachineUpdate()
Esempio n. 27
0
    def run(self, machine):
        address = self.source_word.int_value()
        loaded_word = machine.memory.read_word(address)

        return MachineUpdate(registers={self.dest_register: loaded_word})