From d3e366a591dc0f91edcba49f1e8594d048e0e9f1 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sun, 20 May 2012 21:55:47 +0200 Subject: [PATCH] codegen/div: clear edx before use div insn --- Mate/X86CodeGen.hs | 7 +++---- tests/Div1.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/Div1.java diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index a53e704..a5c9a14 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -29,7 +29,6 @@ import Mate.Types import Mate.Utilities import Mate.ClassPool import Mate.Strings -import Mate.Debug #ifdef DEBUG import Text.Printf #endif @@ -268,7 +267,7 @@ emitFromBB method sig cls hmap = do emit (LDC2 x) = do value <- case constsPool cls M.! x of (CString s) -> liftIO $ getUniqueStringAddr s - _ -> error "LDCI... missing impl." + e -> error $ "LDCI... missing impl.: " ++ show e push value emit (GETFIELD x) = do offset <- emitFieldOffset x @@ -281,8 +280,8 @@ emitFromBB method sig cls hmap = do emit IADD = do pop ebx; pop eax; add eax ebx; push eax emit ISUB = do pop ebx; pop eax; sub eax ebx; push eax emit IMUL = do pop ebx; pop eax; mul ebx; push eax - emit IDIV = do pop ebx; pop eax; div ebx; push eax - emit IREM = do pop ebx; pop eax; div ebx; push edx + emit IDIV = do pop ebx; pop eax; xor edx edx; div ebx; push eax + emit IREM = do pop ebx; pop eax; xor edx edx; div ebx; push edx emit IXOR = do pop ebx; pop eax; xor eax ebx; push eax emit INEG = do pop eax; neg eax; push eax emit (IINC x imm) = diff --git a/tests/Div1.java b/tests/Div1.java new file mode 100644 index 0000000..3e728ba --- /dev/null +++ b/tests/Div1.java @@ -0,0 +1,12 @@ +package tests; + +public class Div1 { + public static void main(String []args) { + int a = 100; + int b = 23; + System.out.printf("%d\n", a / b); + System.out.printf("%d\n", a % b); + System.out.printf("%d\n", b / a); + System.out.printf("%d\n", b % a); + } +} -- 2.25.1