Compare commits

..

2 Commits

Author SHA1 Message Date
cat
e8850f37bc Added storing and outputting values in registry 2026-02-10 02:27:12 +02:00
cat
19b6306927 Added JumpTo 2026-02-10 02:17:08 +02:00

View File

@@ -35,9 +35,16 @@ enum : int {
DivideBy, DivideBy,
ModulusBy, ModulusBy,
SetTo, SetTo,
JumpTo,
Print, Print,
StoreValueIn,
PutValueIn,
// Type // Type
W,
X,
Y,
Z,
AsDigit, AsDigit,
AsUnsignedDigit, AsUnsignedDigit,
AsCharacter, AsCharacter,
@@ -54,7 +61,7 @@ public:
private: private:
Command State = NoCommand; Command State = NoCommand;
std::array<int, maxCells> memory; 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; std::size_t currentPosition = 0;
void Execute(int command) { void Execute(int command) {
@@ -63,7 +70,7 @@ private:
processCommand(command); processCommand(command);
return; return;
// Arithmatic // Arithmetic
case SetTo: case SetTo:
memory[currentPosition] = command; memory[currentPosition] = command;
break; break;
@@ -83,10 +90,21 @@ private:
memory[currentPosition] %= command; memory[currentPosition] %= command;
break; break;
case JumpTo:
currentPosition = command;
break;
case StoreValueIn:
whichRegistry(command) = memory[currentPosition];
break;
case PutValueIn:
memory[currentPosition] = whichRegistry(command);
break;
case Print: case Print:
handlePrint(command); handlePrint(command);
State = NoCommand; break;
return;
default: default:
std::terminate(); std::terminate();
@@ -124,7 +142,10 @@ private:
// Double Argument Commands // Double Argument Commands
case Print: case Print:
case JumpTo:
case SetTo: case SetTo:
case StoreValueIn:
case PutValueIn:
case IncrementBy: case IncrementBy:
case DecrementBy: case DecrementBy:
case MultiplyBy: case MultiplyBy:
@@ -140,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) { void handlePrint(int Type) {
switch (Type) { switch (Type) {
case AsDigit: case AsDigit: