From 7cf7c336a7fb8eb65f0360b18a81d7093ddc8c54 Mon Sep 17 00:00:00 2001 From: Clemens-Dautermann Date: Wed, 23 Dec 2020 11:51:58 +0100 Subject: [PATCH] Fixed the division error. Kinda --- Compiler/DevFunctions.cs | 2 +- Compiler/Generator/Generator.cs | 5 ++--- stage_3/valid/div_2 => div_neg | Bin 16336 -> 16336 bytes test.s | 12 ------------ 4 files changed, 3 insertions(+), 16 deletions(-) rename stage_3/valid/div_2 => div_neg (92%) delete mode 100644 test.s diff --git a/Compiler/DevFunctions.cs b/Compiler/DevFunctions.cs index d9f21cc..f1fb57e 100644 --- a/Compiler/DevFunctions.cs +++ b/Compiler/DevFunctions.cs @@ -112,7 +112,7 @@ namespace Compiler { */ - string file = "/home/clemens/repositorys/lcc/stage_3/valid/div_2.c"; + string file = "/home/clemens/repositorys/lcc/stage_3/valid/div_neg.c"; Console.WriteLine("-------------"); List tokens = TestLexer(file, 0); diff --git a/Compiler/Generator/Generator.cs b/Compiler/Generator/Generator.cs index 1e8fefa..94eef80 100644 --- a/Compiler/Generator/Generator.cs +++ b/Compiler/Generator/Generator.cs @@ -55,7 +55,7 @@ namespace Compiler.Generator case OperatorType.LogicalNegation: s = $"{Generate(rootNode.Children[0])}" + "cmpl $0, %eax\n" + - "movl $0, %eax\n" + //xorl %eax, %eax should also work, but doesn't + "movl $0, %eax\n" + "sete %al\n"; break; default: @@ -95,8 +95,7 @@ namespace Compiler.Generator "movl %eax, %ecx\n" + //move calculated divisor to %ecx "pop %rax\n" + //pop divident do %eax "cdq\n" + - "divl %ecx\n" + - "movl %ecx, %eax\n"; + "divl %ecx\n"; //eax contains the result, edx the rest break; default: throw new ArgumentOutOfRangeException(); diff --git a/stage_3/valid/div_2 b/div_neg similarity index 92% rename from stage_3/valid/div_2 rename to div_neg index 221cd842490e17735ba1c2a0a0a0e2803ac74c95..ce16a2473d24fc90b6c3628c5a2bedfedc63b491 100755 GIT binary patch delta 232 zcmcamf1!Q@2P5ZJMg}n0x>=C%Fr!G!Z{}r_j~fay1QogNNphJ{x5e6W^9v?FUd}W| z1_qB_-uDcX?FDYT@GvkicznMRu!EI>fuZwY#LVv>52sD|%rE!LG2Exu_O%WJgJYOy z=QYPr&(5!oA&#AYLOptQ@8~cv1p8?I^=N*>@nZhwI>9Es$qLL0lN2O4bw2+8AHu-E zFlVx&f<5Df$%zW?tUo^d|IfPlpSpL2yE*h35}Hf!1}X9fVMGE~X{ delta 260 zcmcamf1!Q@2P5ZIMg}mrx>=C%Fr&!aQ_iNAJhxM_Uz>_AIAHK}smS)C%`cezcsbh` z85lfzdHES9+Y8)I;bLH52-pGA+j%fz=J$`CCjxdbF)%P7c&tdg!~F6MAX`53%l&c; z_vy7gt;4|J80Oh|%`w!o^Q&WsW9Oexk6zt9It&cKKAL|$n%{7|sNWnX*u*zUL4wog z