about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2018-09-08 19:16:21 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2018-09-10 08:20:48 +0200
commit9358bf5ad2113fb2d1c8c11e3da59fe8c0c1be13 (patch)
tree21d7ff201f93776c487d12934b0971d86d7797c9
parent8e6b39d80e9f8db8389bd2a8106d0f64b91c19e9 (diff)
downloadmiasm-9358bf5ad2113fb2d1c8c11e3da59fe8c0c1be13.tar.gz
miasm-9358bf5ad2113fb2d1c8c11e3da59fe8c0c1be13.zip
X86: fix aam sem
Diffstat (limited to '')
-rw-r--r--miasm2/arch/x86/sem.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py
index 0cb9f3e2..f87c42cf 100644
--- a/miasm2/arch/x86/sem.py
+++ b/miasm2/arch/x86/sem.py
@@ -3115,15 +3115,28 @@ def das(_, instr):
     return e, []
 
 
-def aam(_, instr, src):
+def aam(ir, instr, src):
     e = []
-    tempAL = mRAX[instr.mode][0:8]
-    newEAX = m2_expr.ExprCompose(m2_expr.ExprOp("umod", tempAL, src),
-                                 m2_expr.ExprOp("udiv", tempAL, src),
-                                 mRAX[instr.mode][16:])
-    e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)]
-    e += update_flag_arith(newEAX)
-    e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1)))
+    assert src.is_int()
+
+    value = int(src)
+    if value:
+        tempAL = mRAX[instr.mode][0:8]
+        newEAX = m2_expr.ExprCompose(
+            m2_expr.ExprOp("umod", tempAL, src),
+            m2_expr.ExprOp("udiv", tempAL, src),
+            mRAX[instr.mode][16:]
+        )
+        e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)]
+        e += update_flag_arith(newEAX)
+        e.append(m2_expr.ExprAff(af, m2_expr.ExprInt(0, 1)))
+    else:
+        e.append(
+            m2_expr.ExprAff(
+                exception_flags,
+                m2_expr.ExprInt(EXCEPT_DIV_BY_ZERO, exception_flags.size)
+            )
+        )
     return e, []