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 221cd84..ce16a24 100755 Binary files a/stage_3/valid/div_2 and b/div_neg differ diff --git a/test.s b/test.s deleted file mode 100644 index 5116b4f..0000000 --- a/test.s +++ /dev/null @@ -1,12 +0,0 @@ -.globl main -main: -movl $3, %eax -push %rax -movl $2, %eax -pop %rcx -sub %ecx, %eax -push %rax -movl $1, %eax -pop %rcx -sub %ecx, %eax -ret