Files
dbowerman eae5314e3b 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.
2026-06-03 09:54:36 -04:00

60 lines
2.0 KiB
C#

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");
_instructionSet.Add("00010", "STORE");
_instructionSet.Add("00011", "ADD");
_instructionSet.Add("00100", "SUB");
_instructionSet.Add("00101", "JUMP");
_instructionSet.Add("00110", "JUMPIFZERO");
_instructionSet.Add("00111", "JUMPIFNEG");
_instructionSet.Add("01000", "AND");
_instructionSet.Add("01001", "OR");
_instructionSet.Add("01010", "XOR");
_instructionSet.Add("01011", "NOT");
_instructionSet.Add("01100", "SHL");
_instructionSet.Add("01101", "SHR");
_instructionSet.Add("01110", "INC");
_instructionSet.Add("01111", "DEC");
_registers = new Dictionary<string, Word>();
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);
}
}
internal class ProgramCounter
{
Int16 _value;
public ProgramCounter()
{
_value = 0;
}
public void Increment()
{
_value++;
}
public void SetValue(string value)
{
_value = Convert.ToInt16(value, 2);
}
public string GetValue()
{
return Utils.Int16ToBinaryString(_value);
}
}
}
}