implemented assembly for addition, substraction and multiplication. Division is not working yet
This commit is contained in:
parent
66417bb16e
commit
120a575b15
5 changed files with 134 additions and 69 deletions
|
|
@ -63,6 +63,44 @@ namespace Compiler.Generator
|
|||
((UnaryOperatorNode) rootNode).OperatorType);
|
||||
}
|
||||
|
||||
break;
|
||||
case NodeType.BinaryOperatorNode:
|
||||
switch (((BinaryOperatorNode) rootNode).OperatorType)
|
||||
{
|
||||
case OperatorType.Addition:
|
||||
s = $"{Generate(rootNode.Children[0])}" +
|
||||
"push %rax\n" +
|
||||
$"{Generate(rootNode.Children[1])}" +
|
||||
"pop %rcx\n" +
|
||||
"add %ecx, %eax\n";
|
||||
break;
|
||||
case OperatorType.Subtraction:
|
||||
s = $"{Generate(rootNode.Children[1])}" +
|
||||
"push %rax\n" +
|
||||
$"{Generate(rootNode.Children[0])}" +
|
||||
"pop %rcx\n" +
|
||||
"sub %ecx, %eax\n";
|
||||
break;
|
||||
case OperatorType.Multiplication:
|
||||
s = $"{Generate(rootNode.Children[0])}" +
|
||||
"push %rax\n" +
|
||||
$"{Generate(rootNode.Children[1])}" +
|
||||
"pop %rcx\n" +
|
||||
"imul %rcx, %rax\n";
|
||||
break;
|
||||
case OperatorType.Division:
|
||||
s = $"{Generate(rootNode.Children[0])}" +
|
||||
"push %rax\n" +
|
||||
$"{Generate(rootNode.Children[1])}" +
|
||||
"movl %eax, %ecx" + //move calculated divisor to %ecx
|
||||
"pop %rbx\n" + //pop divident do %ebx
|
||||
"cdq\n" +
|
||||
"idivl %ecx\n";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new NotSpecifiedException(rootNode.NodeType);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue