diff options
author | Tom Stellard <tstellar@gmail.com> | 2010-12-28 22:28:32 -0800 |
---|---|---|
committer | Tom Stellard <tstellar@gmail.com> | 2010-12-28 22:28:32 -0800 |
commit | f5c76883babf67f33d8b52bf32abc71176f92c8b (patch) | |
tree | fada2fb9aeaedaf41210a5c90784ece261f41c77 | |
parent | 9e18507a1ee455bacb2a72bb8e641242f2ed5baf (diff) |
Add mul instruction
-rw-r--r-- | evaluator.cpp | 18 | ||||
-rw-r--r-- | evaluator.h | 9 | ||||
-rw-r--r-- | instruction.cpp | 16 | ||||
-rw-r--r-- | instruction.h | 6 |
4 files changed, 49 insertions, 0 deletions
diff --git a/evaluator.cpp b/evaluator.cpp index 954a488..0d50b98 100644 --- a/evaluator.cpp +++ b/evaluator.cpp @@ -91,3 +91,21 @@ add_evaluator::evaluate( new_val->set_value(l->m_value + r->m_value); return new_val; } + +mul_evaluator::mul_evaluator() : + evaluator("*") + { } + +value * +mul_evaluator::evaluate( + float_value * l, + float_value * r) +{ + float_value * new_val; + if (!l || !r || !l->m_has_value || !r->m_has_value) { + return default_evaluate(l,r); + } + + new_val = new float_value(l->m_value * r->m_value); + return new_val; +} diff --git a/evaluator.h b/evaluator.h index 26594f0..2dd0c70 100644 --- a/evaluator.h +++ b/evaluator.h @@ -39,4 +39,13 @@ public: float_value * r); }; + +class mul_evaluator : public evaluator { +public: + mul_evaluator(); + value * evaluate( + float_value * l, + float_value * r); +}; + #endif //EVALUATOR_H_ diff --git a/instruction.cpp b/instruction.cpp index 1e7f91b..41d4987 100644 --- a/instruction.cpp +++ b/instruction.cpp @@ -72,3 +72,19 @@ mov_instruction::execute(emulator & emulator) emulator.get_value(m_src_regs[0][i])); } } + +mul_instruction::mul_instruction(std::vector<register_address> dst) : + instruction("MUL", new mul_evaluator(), dst, 2) + { } + +void +mul_instruction::execute(emulator & emulator) +{ + unsigned int i; + for (i = 0; i < m_dst.size(); i++) { + tree_value * val = new tree_value(this->m_evaluator, + emulator.get_value(m_src_regs[0][i]), + emulator.get_value(m_src_regs[1][i])); + emulator.set_value(m_dst[i], val); + } +} diff --git a/instruction.h b/instruction.h index a41392b..10c61b9 100644 --- a/instruction.h +++ b/instruction.h @@ -49,4 +49,10 @@ public: void execute(emulator & emulator); }; +class mul_instruction : public instruction { +public: + mul_instruction(std::vector<register_address> dst); + void execute(emulator & emulator); +}; + #endif //INSTRUCTION_H_ |