From 6557e7e623140871968776429d241570002a65f5 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 12:33:25 -0400 Subject: Setting condition code register, overflow guard --- inc/definitions.h | 6 ++++++ inc/ex.h | 18 ++++++++++++++++++ inc/instr.h | 1 - inc/stage.h | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/definitions.h b/inc/definitions.h index 3238a8b..c81c4e3 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -76,6 +76,12 @@ */ #define OPCODE_SIZE 4 +/** + * The maximum value an integer can hold. + * The minimum is always this number plus one negated. + */ +#define MAX_INT 2147483647 + /** * Return the N least-significant bits from integer K using a bit mask * @param the integer to be parsed diff --git a/inc/ex.h b/inc/ex.h index 2ca8876..4edf873 100644 --- a/inc/ex.h +++ b/inc/ex.h @@ -3,6 +3,7 @@ #include "instrDTO.h" #include "response.h" #include "stage.h" +#include class EX : public Stage { @@ -15,6 +16,23 @@ class EX : public Stage EX(Stage *next); InstrDTO *advance(Response p) override; + + private: + /** + * Sets the (over|under)flow condition code if adding `a` and `b` results in + * either. + * @param the first operand + * @param the second operand + */ + void overflow_guard(signed int a, signed int b); + /** + * Maps each mnemonic to a function which carries out the instruction's base + * logic. + */ + std::unordered_map< + Mnemonic, + std::function> + instr_map; }; #endif /* EX_H_INCLUDED */ diff --git a/inc/instr.h b/inc/instr.h index 08b4fd0..7fbb42b 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -49,7 +49,6 @@ namespace instr { // clang-format off extern const std::unordered_map mnemonic_map; - extern const std::unordered_map> instr_map; // clang-format on } // namespace instr diff --git a/inc/stage.h b/inc/stage.h index 50c413a..c0dc6a8 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -9,6 +9,13 @@ #include #include +enum CC { + GT, + EQ, + UF, + OF, +}; + class Stage { public: @@ -30,6 +37,17 @@ class Stage virtual InstrDTO *advance(Response p) = 0; protected: + /** + * Sets the bit in the condition code register corresponding to `c`. + * @param the condition code to set. + * @param the truthy value to set it to. + */ + void set_condition(CC c, bool v); + /** + * Gets the bit in the condition code register correspondng to `c`. + * @param the condition code to retrieve, + */ + bool get_condition(CC c); /** * Helper for `check_out`. * Returns true if r are not checked out, false otherwise. -- cgit v1.2.3