diff options
author | bd <bdunaisky@umass.edu> | 2025-04-18 00:58:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-18 00:58:40 +0000 |
commit | 480181957b3f3dbcf7731023504c2cacc8d181ea (patch) | |
tree | e936781b52c6846d87c98381ed47bc7da7c43bff /src/sim/ex.cc | |
parent | 62b9e280d5d0222710e491dcd28fe26bea915dcd (diff) | |
parent | 984ce6eef2e439955ff991f90c2b654be7c6c3f3 (diff) |
Merge pull request #54 from bdunahu/bdunahu
The pipeline says some things and there are numbers
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; + } +} |