Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing instrs #27

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions interp_x86/eval_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand Down
6 changes: 6 additions & 0 deletions interp_x86/parser_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down