Compare commits

...

3 Commits

Author SHA1 Message Date
cat
c8d565d8b2 Setting values on registries 2026-02-10 02:41:29 +02:00
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,19 @@ enum : int {
DivideBy, DivideBy,
ModulusBy, ModulusBy,
SetTo, SetTo,
JumpTo,
Print, Print,
// Registry
StoreValueIn,
PutValueIn,
SetValueIn, // Three Argumens!!
// Type // Type
W,
X,
Y,
Z,
AsDigit, AsDigit,
AsUnsignedDigit, AsUnsignedDigit,
AsCharacter, AsCharacter,
@@ -53,8 +63,9 @@ public:
private: private:
Command State = NoCommand; Command State = NoCommand;
int selectedRegistry = 0;
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 +74,7 @@ private:
processCommand(command); processCommand(command);
return; return;
// Arithmatic // Arithmetic
case SetTo: case SetTo:
memory[currentPosition] = command; memory[currentPosition] = command;
break; break;
@@ -83,10 +94,28 @@ 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 SetValueIn:
if (selectedRegistry == 0) {
selectedRegistry = command;
return;
}
whichRegistry(selectedRegistry) = command;
selectedRegistry = 0;
break;
case Print: case Print:
handlePrint(command); handlePrint(command);
State = NoCommand; break;
return;
default: default:
std::terminate(); std::terminate();
@@ -94,7 +123,7 @@ private:
} }
// This is only called after multi-argument functions are done // This is only called after multi-argument functions are done
if (State != NoCommand) { if (State != NoCommand && selectedRegistry == 0) {
State = NoCommand; State = NoCommand;
return; return;
} }
@@ -122,8 +151,14 @@ private:
--memory[currentPosition]; --memory[currentPosition];
return; return;
// Double Argument Commands // Multi Argument Commands
case Print: case Print:
case JumpTo:
case StoreValueIn:
case PutValueIn:
case SetValueIn:
case SetTo: case SetTo:
case IncrementBy: case IncrementBy:
case DecrementBy: case DecrementBy:
@@ -140,6 +175,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: