예제 #1
0
    def JMP(self):
        # print("JMP")

        if self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("JMP: Bad Parameter 1", self.IP)

        self.IP = self.memory[self.IP + 1]
        return True
예제 #2
0
    def CMP(self):
        # print("CMP")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("CMP: Bad Parameter 1", self.IP)

        if self.parameter2Mode == self.REFERENCE:
            raise ExcecutionError("CMP: Bad Parameter 2", self.IP)

        value1 = self.determineValue(self.parameter1Mode,
                                     self.memory[self.IP + 1])
        value2 = self.determineValue(self.parameter2Mode,
                                     self.memory[self.IP + 2])

        self.setFlagsFromResult(value1 - value2)

        self.IP += 3
        return True
예제 #3
0
    def STOR(self):
        # print("STOR")

        if self.parameter1Mode != self.REGISTER and self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("STOR: Bad Parameter 1", self.IP)

        if self.parameter2Mode != self.REFERENCE and self.parameter2Mode != self.INDEXED:
            raise ExcecutionError("STOR: Bad Parameter 2", self.IP)

        value = self.determineValue(self.parameter1Mode,
                                    self.memory[self.IP + 1])
        ref = self.getRegister(self.memory[self.IP + 2])
        if self.parameter2Mode == self.INDEXED:
            ref += self.IX
        self.setMemory(ref, self.makeWord(value))

        self.IP += 3
        return True
예제 #4
0
    def CALL(self):
        # print("CALL")

        if self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("CALL: Bad Parameter 1", self.IP)

        self.memory[self.SP] = self.IP + 2
        self.SP += 1

        self.IP = self.memory[self.IP + 1]

        return True
예제 #5
0
    def POP(self):
        # print("POP")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("POP: Bad Parameter 1", self.IP)

        self.SP -= 1
        value = self.memory[self.SP]
        self.setRegister(self.memory[self.IP + 1], value)

        self.IP += 2
        return True
예제 #6
0
    def PUSH(self):
        # print("PUSH")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("PUSH: Bad Parameter 1", self.IP)

        value = self.getRegister(self.memory[self.IP + 1])
        self.memory[self.SP] = value
        self.SP += 1

        self.IP += 2
        return True
예제 #7
0
    def XOR(self):
        # print("XOR")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("XOR: Bad Parameter 1", self.IP)

        if self.parameter2Mode == self.REFERENCE:
            raise ExcecutionError("XOR: Bad Parameter 2", self.IP)

        value1 = self.getRegister(self.memory[self.IP + 1])
        value2 = self.determineValue(self.parameter2Mode,
                                     self.memory[self.IP + 2])

        value1 = value1 ^ value2

        self.setRegister(self.memory[self.IP + 1], value1)

        self.setFlagsFromResult(value1)

        self.IP += 3
        return True
예제 #8
0
    def DIV(self):
        # print("DIV")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("MUL: Bad Parameter 1", self.IP)

        if self.parameter2Mode == self.REFERENCE:
            raise ExcecutionError("MUL: Bad Parameter 2", self.IP)

        value1 = self.getRegister(self.memory[self.IP + 1])
        value2 = self.determineValue(self.parameter2Mode,
                                     self.memory[self.IP + 2])

        r = value1 % value2
        q = value1 // value2

        self.setRegister(self.memory[self.IP + 1], q)
        self.setRegister(Definitions.registers["DX"], r)

        self.IP += 3
        return True
예제 #9
0
    def JGE(self):
        # print("JGE")

        if self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("JGE: Bad Parameter 1", self.IP)

        if self.OF() == self.SF():
            self.IP = self.memory[self.IP + 1]
        else:
            self.IP += 2

        return True
예제 #10
0
    def JNC(self):
        # print("JNC")

        if self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("JC: Bad Parameter 1", self.IP)

        if self.CF() == False:
            self.IP = self.memory[self.IP + 1]
        else:
            self.IP += 2

        return True
예제 #11
0
    def JZ(self):
        # print("JZ")

        if self.parameter1Mode != self.DIRECT:
            raise ExcecutionError("JZ: Bad Parameter 1", self.IP)

        if self.ZF() == True:
            self.IP = self.memory[self.IP + 1]
        else:
            self.IP += 2

        return True
예제 #12
0
    def SHR(self):
        # print("SHR")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("SHR: Bad Parameter 1", self.IP)

        param1 = self.memory[self.IP + 1]
        value = self.getRegister(param1)
        value = value >> 1
        self.setFlagsFromResult(value)
        self.setRegister(param1, value)

        self.IP += 2
        return True
예제 #13
0
    def MOV(self):
        # print("MOV")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("MOV: Bad Parameter 1", self.IP)

        regTo = self.memory[self.IP + 1]
        value = self.determineValue(self.parameter2Mode,
                                    self.memory[self.IP + 2])

        self.setRegister(regTo, value)

        self.IP += 3
        return True
예제 #14
0
    def NOT(self):
        # print("NOT")

        if self.parameter1Mode != self.REGISTER:
            raise ExcecutionError("XOR: Bad Parameter 1", self.IP)

        value1 = self.getRegister(self.memory[self.IP + 1])
        value1 = ~value1

        self.setRegister(self.memory[self.IP + 1], value1)

        self.setFlagsFromResult(value1)

        self.IP += 2
        return True
예제 #15
0
    def loadProgram(self, program: Program) -> None:
        if program.assembled == False:
            raise ExcecutionError("Program not compiled", 0)

        for ix, byte in enumerate(program.binary):
            self.memory[ix] = byte