Added storing and outputting values in registry
This commit is contained in:
35
machine.hpp
35
machine.hpp
@@ -37,8 +37,14 @@ enum : int {
|
|||||||
SetTo,
|
SetTo,
|
||||||
JumpTo,
|
JumpTo,
|
||||||
Print,
|
Print,
|
||||||
|
StoreValueIn,
|
||||||
|
PutValueIn,
|
||||||
|
|
||||||
// Type
|
// Type
|
||||||
|
W,
|
||||||
|
X,
|
||||||
|
Y,
|
||||||
|
Z,
|
||||||
AsDigit,
|
AsDigit,
|
||||||
AsUnsignedDigit,
|
AsUnsignedDigit,
|
||||||
AsCharacter,
|
AsCharacter,
|
||||||
@@ -55,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) {
|
||||||
@@ -87,6 +93,15 @@ private:
|
|||||||
case JumpTo:
|
case JumpTo:
|
||||||
currentPosition = command;
|
currentPosition = command;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case StoreValueIn:
|
||||||
|
whichRegistry(command) = memory[currentPosition];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PutValueIn:
|
||||||
|
memory[currentPosition] = whichRegistry(command);
|
||||||
|
break;
|
||||||
|
|
||||||
case Print:
|
case Print:
|
||||||
handlePrint(command);
|
handlePrint(command);
|
||||||
break;
|
break;
|
||||||
@@ -129,6 +144,8 @@ private:
|
|||||||
case Print:
|
case Print:
|
||||||
case JumpTo:
|
case JumpTo:
|
||||||
case SetTo:
|
case SetTo:
|
||||||
|
case StoreValueIn:
|
||||||
|
case PutValueIn:
|
||||||
case IncrementBy:
|
case IncrementBy:
|
||||||
case DecrementBy:
|
case DecrementBy:
|
||||||
case MultiplyBy:
|
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) {
|
void handlePrint(int Type) {
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case AsDigit:
|
case AsDigit:
|
||||||
|
|||||||
Reference in New Issue
Block a user