diff options
Diffstat (limited to 'src/sim/ex.cc')
-rw-r--r-- | src/sim/ex.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/sim/ex.cc b/src/sim/ex.cc index d20d15f..62e39c1 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; @@ -340,20 +340,18 @@ EX::EX(Stage *stage) : Stage(stage) INIT_INSTRUCTION( PUSH, { + s1 = s1 + s3; (void)pc; - (void)s3; (void)s2; - (void)s1; (void)this; }), INIT_INSTRUCTION( POP, { + s1 = s1 + s3; (void)pc; - (void)s3; (void)s2; - (void)s1; (void)this; }), @@ -387,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; + } +} |