diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-10 22:27:23 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-10 22:27:23 +0000 |
commit | e065e781448b86eeeca0152f735649ea2a2edbb6 (patch) | |
tree | 314a4b403456096c37eceb9559f0b40f29e03079 | |
parent | 27134d31ce42631fca12295f4064d55de8dfdee8 (diff) | |
download | Compiler-e065e781448b86eeeca0152f735649ea2a2edbb6.tar.gz Compiler-e065e781448b86eeeca0152f735649ea2a2edbb6.zip |
Can do multiple adds and subs
-rw-r--r-- | c_compiler/src/expression.cpp | 6 | ||||
-rw-r--r-- | c_compiler/test/in/Add.c | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp index fb5b62b..cd20e24 100644 --- a/c_compiler/src/expression.cpp +++ b/c_compiler/src/expression.cpp @@ -68,12 +68,12 @@ AdditiveExpression::AdditiveExpression(Expression* _lhs, const std::string& _ope VariableStackBindings AdditiveExpression::printasm(VariableStackBindings bindings) const { - rhs->printasm(bindings); + lhs->printasm(bindings); // move the rhs out of the way to be able to evaluate the lhs std::cout << "\tmove\t$3,$2" << std::endl; - lhs->printasm(bindings); + rhs->printasm(bindings); // then perform the right operation @@ -82,7 +82,7 @@ VariableStackBindings AdditiveExpression::printasm(VariableStackBindings binding if(operation == "+") std::cout << "\tadd\t$2,$2,$3" << std::endl; else if(operation == "-") - std::cout << "\tsub\t$2,$2,$3" << std::endl; + std::cout << "\tsub\t$2,$3,$2" << std::endl; else std::cerr << "Don't recognize symbol: '" << operation << "'" << std::endl; diff --git a/c_compiler/test/in/Add.c b/c_compiler/test/in/Add.c index acdcffc..43e557e 100644 --- a/c_compiler/test/in/Add.c +++ b/c_compiler/test/in/Add.c @@ -5,7 +5,7 @@ int main() { { { - z = x + y; + z = x + y + x + y - x; } } |