Fixed the division error. Kinda
This commit is contained in:
parent
72023962f5
commit
7cf7c336a7
4 changed files with 3 additions and 16 deletions
|
|
@ -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("-------------");
|
Console.WriteLine("-------------");
|
||||||
List<Token> tokens = TestLexer(file, 0);
|
List<Token> tokens = TestLexer(file, 0);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Compiler.Generator
|
||||||
case OperatorType.LogicalNegation:
|
case OperatorType.LogicalNegation:
|
||||||
s = $"{Generate(rootNode.Children[0])}" +
|
s = $"{Generate(rootNode.Children[0])}" +
|
||||||
"cmpl $0, %eax\n" +
|
"cmpl $0, %eax\n" +
|
||||||
"movl $0, %eax\n" + //xorl %eax, %eax should also work, but doesn't
|
"movl $0, %eax\n" +
|
||||||
"sete %al\n";
|
"sete %al\n";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -95,8 +95,7 @@ namespace Compiler.Generator
|
||||||
"movl %eax, %ecx\n" + //move calculated divisor to %ecx
|
"movl %eax, %ecx\n" + //move calculated divisor to %ecx
|
||||||
"pop %rax\n" + //pop divident do %eax
|
"pop %rax\n" + //pop divident do %eax
|
||||||
"cdq\n" +
|
"cdq\n" +
|
||||||
"divl %ecx\n" +
|
"divl %ecx\n"; //eax contains the result, edx the rest
|
||||||
"movl %ecx, %eax\n";
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
|
|
|
||||||
Binary file not shown.
12
test.s
12
test.s
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue