From e8850f37bcb69c70d79dfe1340d8f2035a51238c Mon Sep 17 00:00:00 2001 From: cat Date: Tue, 10 Feb 2026 02:27:12 +0200 Subject: [PATCH] Added storing and outputting values in registry --- machine.hpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/machine.hpp b/machine.hpp index 9d558b2..411ab40 100644 --- a/machine.hpp +++ b/machine.hpp @@ -37,8 +37,14 @@ enum : int { SetTo, JumpTo, Print, + StoreValueIn, + PutValueIn, // Type + W, + X, + Y, + Z, AsDigit, AsUnsignedDigit, AsCharacter, @@ -55,7 +61,7 @@ public: private: Command State = NoCommand; std::array memory; - int W = 0, X = 0, Y = 0, Z = 0; + int RW = 0, RX = 0, RY = 0, RZ = 0; std::size_t currentPosition = 0; void Execute(int command) { @@ -87,6 +93,15 @@ private: case JumpTo: currentPosition = command; break; + + case StoreValueIn: + whichRegistry(command) = memory[currentPosition]; + break; + + case PutValueIn: + memory[currentPosition] = whichRegistry(command); + break; + case Print: handlePrint(command); break; @@ -129,6 +144,8 @@ private: case Print: case JumpTo: case SetTo: + case StoreValueIn: + case PutValueIn: case IncrementBy: case DecrementBy: case MultiplyBy: @@ -144,6 +161,22 @@ private: } } + int &whichRegistry(int Type) { + switch (Type) { + case W: + return RW; + case X: + return RX; + case Y: + return RY; + case Z: + return RZ; + + default: + std::terminate(); + } + } + void handlePrint(int Type) { switch (Type) { case AsDigit: