diff --git a/interp_x86/eval_x86.py b/interp_x86/eval_x86.py index a1a9b6a..478ba26 100644 --- a/interp_x86/eval_x86.py +++ b/interp_x86/eval_x86.py @@ -406,6 +406,24 @@ def eval_instrs(self, instrs, blocks, output): self.eval_instrs(blocks[target], blocks, output) return # after jumping, toss continuation + elif instr.data == 'andq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, and64(v1, v2)) + + elif instr.data == 'salq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, v2 << v1) + + elif instr.data == 'sarq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, v2 >> v1) + else: raise RuntimeError(f'Unknown instruction: {instr.data}') diff --git a/interp_x86/parser_x86.py b/interp_x86/parser_x86.py index ef158e4..3e0c9f1 100644 --- a/interp_x86/parser_x86.py +++ b/interp_x86/parser_x86.py @@ -25,6 +25,9 @@ | "setge" arg -> setge | "movzbq" arg "," arg -> movzbq | "xorq" arg "," arg -> xorq + | "andq" arg "," arg -> andq + | "salq" arg "," arg -> salq + | "sarq" arg "," arg -> sarq | "callq" CNAME -> callq | "callq" "*" arg -> indirect_callq | "pushq" arg -> pushq @@ -81,6 +84,9 @@ | "movzbq" arg "," arg -> movzbq | "xorq" arg "," arg -> xorq | "callq" CNAME -> callq + | "andq" arg "," arg -> andq + | "salq" arg "," arg -> salq + | "sarq" arg "," arg -> sarq | "callq" "*" arg -> indirect_callq | "pushq" arg -> pushq | "popq" arg -> popq diff --git a/utils.py b/utils.py index 8399df4..1fb32d0 100644 --- a/utils.py +++ b/utils.py @@ -1087,6 +1087,9 @@ def neg64(x): def xor64(x,y): return to_signed(x^y) +def and64(x,y): + return to_singed(x&y) + def is_int64(x) -> bool: return isinstance(x,int) and (x >= min_int64 and x <= max_int64)