1
0

Added checks in compareVal to set status-keys l and e to signify

respectively 'lower than' and 'equal to'.
Added the following control flow operations:
* jl (less than)
* je (equal to)
* jge (greater than or equal to)
* jle (less than or equal to)
* jne (not equal to)
This commit is contained in:
Christoffer Müller Madsen 2015-12-16 22:20:33 +01:00
parent 658d045846
commit 0701838950

View File

@ -123,8 +123,9 @@ class Emulator:
def compareVal (self, valT1, valT2): def compareVal (self, valT1, valT2):
val1 = self.getVal(valT2) val1 = self.getVal(valT2)
val2 = self.getVal(valT1) val2 = self.getVal(valT1)
self.status = {"g":val1>val2} self.status["g"] = val1>val2
self.status["l"] = val1<val2
self.status["e"] = val1==val2
def changedRegisters (self, *args): def changedRegisters (self, *args):
for reg, val in args: for reg, val in args:
self.changes[reg] = val self.changes[reg] = val
@ -193,6 +194,21 @@ class Emulator:
elif opcode == "jg": elif opcode == "jg":
if self.status["g"]: if self.status["g"]:
self.registers['%rip'] = self.labels[instruct[1]] self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "jl":
if self.status["l"]:
self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "je":
if self.status["e"]:
self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "jge":
if (self.status["g"] or self.status["e"]):
self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "jle":
if (self.status["l"] or self.status["e"]):
self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "jne":
if not self.status["e"]:
self.registers['%rip'] = self.labels[instruct[1]]
elif opcode == "jmp": elif opcode == "jmp":
self.registers['%rip'] = self.labels[instruct[1]] self.registers['%rip'] = self.labels[instruct[1]]