1
0

Merge branch 'master' into 'master'

Added new status flags for comparison. Added new instructions.

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)

See merge request !1
This commit is contained in:
Jon Michael Aanes 2015-12-16 17:33:28 -05:00
commit 3f21bb52e3

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