summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-21 23:00:25 -0400
committerbd <bdunahu@operationnull.com>2025-04-21 23:00:25 -0400
commitcf8f181af044141f754404c1174bc3317a123d93 (patch)
tree866234fe4b367959f566e947c1395ea317559500
parent98b9786ccab6fdee37a779fdd55b58176abf12d9 (diff)
add RET instruction
-rw-r--r--gui/gui.h2
-rw-r--r--inc/instr.h1
-rw-r--r--src/sim/ex.cc10
-rw-r--r--src/sim/id.cc5
-rw-r--r--src/sim/instr.cc2
-rw-r--r--src/sim/wb.cc2
6 files changed, 18 insertions, 4 deletions
diff --git a/gui/gui.h b/gui/gui.h
index cf31142..7b03f75 100644
--- a/gui/gui.h
+++ b/gui/gui.h
@@ -160,7 +160,7 @@ class GUI : public QMainWindow
{Mnemonic::BEQ, "BEQ"}, {Mnemonic::BGT, "BGT"},
{Mnemonic::BUF, "BUF"}, {Mnemonic::BOF, "BOF"},
{Mnemonic::PUSH, "PUSH"}, {Mnemonic::POP, "POP"},
- {Mnemonic::NOP, "NOP"},
+ {Mnemonic::NOP, "NOP"}, {Mnemonic::RET, "RET"},
};
QString mnemonicToString(Mnemonic mnemonic)
{
diff --git a/inc/instr.h b/inc/instr.h
index b5b782a..62af09a 100644
--- a/inc/instr.h
+++ b/inc/instr.h
@@ -58,6 +58,7 @@ enum Mnemonic {
BOF,
PUSH,
POP,
+ RET,
NOP,
};
diff --git a/src/sim/ex.cc b/src/sim/ex.cc
index f098917..4db9fa7 100644
--- a/src/sim/ex.cc
+++ b/src/sim/ex.cc
@@ -372,6 +372,16 @@ EX::EX(Stage *stage) : Stage(stage)
(void)this;
}),
+ INIT_INSTRUCTION(
+ RET,
+ {
+ (void)pc;
+ (void)s3;
+ (void)s2;
+ (void)s1;
+ (void)this;
+ }),
+
/* NOP */
INIT_INSTRUCTION(
NOP,
diff --git a/src/sim/id.cc b/src/sim/id.cc
index 3753f83..cdbaba9 100644
--- a/src/sim/id.cc
+++ b/src/sim/id.cc
@@ -211,8 +211,11 @@ void ID::decode_J_type(
}
this->status = r1;
break;
+ case RET:
+ s1 = 1; // link register
+ [[fallthrough]];
default:
- this->status = this->read_guard(*&s1);
+ this->status = this->read_guard(s1);
}
}
diff --git a/src/sim/instr.cc b/src/sim/instr.cc
index c8d1039..9bd951b 100644
--- a/src/sim/instr.cc
+++ b/src/sim/instr.cc
@@ -35,6 +35,6 @@ const std::unordered_map<unsigned int, Mnemonic> mnemonic_map = {
{0b0101101, STOREV}, {0b0000110, JMP}, {0b0001010, JRL},
{0b0001110, JAL}, {0b0010010, BEQ}, {0b0010110, BGT},
{0b0011010, BUF}, {0b0011110, BOF}, {0b0100010, PUSH},
- {0b0100110, POP},
+ {0b0100110, POP}, {0b0101010, RET},
};
} // namespace instr
diff --git a/src/sim/wb.cc b/src/sim/wb.cc
index fbbdd4c..0348b51 100644
--- a/src/sim/wb.cc
+++ b/src/sim/wb.cc
@@ -62,7 +62,7 @@ void WB::jump_handler()
{
if (this->curr_instr->get_s1() > 0) {
if (this->curr_instr->get_mnemonic() == JAL)
- this->gprs[1] = this->pc + 1;
+ this->gprs[1] = this->curr_instr->get_pc() + 1;;
this->pc = this->curr_instr->get_s1();
this->checked_out = {};
this->next->squash();