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
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
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
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
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
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
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
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
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
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
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
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
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
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
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