summaryrefslogtreecommitdiff
path: root/src/sim/ex.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/ex.cc')
-rw-r--r--src/sim/ex.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/sim/ex.cc b/src/sim/ex.cc
index a32105f..762e847 100644
--- a/src/sim/ex.cc
+++ b/src/sim/ex.cc
@@ -49,15 +49,15 @@ EX::EX(Stage *stage) : Stage(stage)
INIT_INSTRUCTION(
QUOT,
{
- s1 = s1 / s2;
+ this->handle_divide(s1, s2, false);
(void)pc;
(void)s3;
- (void)this;
}),
INIT_INSTRUCTION(
REM,
{
+ this->handle_divide(s1, s2, true);
s1 = s1 % s2;
(void)pc;
(void)s3;
@@ -385,3 +385,15 @@ void EX::advance_helper()
this->curr_instr->set_s1(s1);
this->status = OK;
}
+
+void EX::handle_divide(signed int &s1, signed int s2, bool is_mod)
+{
+ if (s2 == 0) {
+ // handle everything here
+ this->curr_instr->set_s1(MAX_INT);
+ this->status = OK;
+ throw HaltException();
+ } else {
+ s1 = (is_mod) ? s1 / s2 : s1 % s2;
+ }
+}