Added storing and outputting values in registry

This commit is contained in:
2026-02-10 02:27:12 +02:00
parent 19b6306927
commit e8850f37bc

View File

@@ -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<int, maxCells> 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: