added a new ToString method to Word, DWord, and QWord classes.

The ToString method will concatenate the string representations of the high and low words (or dwords) to create a single string representation of the entire word.
This can be used to more easily write and read the value from the MC and CU classes.
This commit is contained in:
2026-06-03 09:54:36 -04:00
parent faa7801376
commit eae5314e3b
15 changed files with 132 additions and 18 deletions
+11 -7
View File
@@ -2,10 +2,12 @@ namespace CPUSimulation
{
public class CU // Control Unit
{
int numberOfRegisters = 16;
Dictionary<string, string> _instructionSet;
Dictionary<string, Word> _registers;
public CU(int numberOfMemoryBanks)
{
_instructionSet = new Dictionary<string, string>();
_instructionSet.Add("00000", "NOP");
_instructionSet.Add("00001", "LOAD");
@@ -25,9 +27,11 @@ namespace CPUSimulation
_instructionSet.Add("01111", "DEC");
_registers = new Dictionary<string, Word>();
for (int i = 0; i < numberOfMemoryBanks; i++)
{
_registers.Add($"R{i}", new Word(new Byte[0]));
Word zeroWord = new Word(new Byte[2] { new Byte("00000000"), new Byte("00000000") });
for (int i = 0; i < numberOfRegisters; i++)
{
string registerName = ((byte)i).ToString().Substring(4, 4);
_registers.Add(registerName, zeroWord);
}
}
@@ -43,13 +47,13 @@ namespace CPUSimulation
{
_value++;
}
public void SetValue(Int16 value)
public void SetValue(string value)
{
_value = value;
_value = Convert.ToInt16(value, 2);
}
public Int16 GetValue()
public string GetValue()
{
return _value;
return Utils.Int16ToBinaryString(_value);
}
}
}