Beginning to add Program Counter and Stack Pointer

Beginning to add initil Instruction Set
This commit is contained in:
2026-05-31 21:29:23 -04:00
parent a958d11c4e
commit faa7801376
5 changed files with 84 additions and 30 deletions
+12 -24
View File
@@ -4,18 +4,14 @@ namespace CPUSimulation
{
public class CPU
{
static Random _random = new Random();
static int numberOfMemoryBanks = 4;
static int memoryBankSize = 1024;
static MC _memoryController;
public static void Main(string[] args)
{
_memoryController = new MC(4, 32768);
for (int i = 0; i < 32768; i++)
{
Word dataToWrite = GenerateRandomWord(_random.Next(1, 5));
_memoryController.Write((Int16)i, dataToWrite);
//Word dataRead = _memoryController.Read((Int16)i);
//Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead.ToString()}");
}
InitilizeMemoryController();
_memoryController.Write("0000000000000001","0000000011110000");
_memoryController.Write("0000000000000010","1111000000001111");
@@ -26,24 +22,16 @@ namespace CPUSimulation
}
}
private static Word GenerateRandomWord(int byteCount)
private static void InitilizeMemoryController()
{
//Console.WriteLine($"Generating random word with {byteCount} bytes.");
Byte[] bytes = new Byte[byteCount];
for (int i = 0; i < byteCount; i++)
_memoryController = new MC(numberOfMemoryBanks, memoryBankSize);
for (int i = 0; i < memoryBankSize; i++)
{
bytes[i] = GenerateRandomByte();
Word dataToWrite = Utils.GenerateRandomWord(numberOfMemoryBanks);
_memoryController.Write((Int16)i, dataToWrite);
//Word dataRead = _memoryController.Read((Int16)i);
//Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead.ToString()}");
}
return new Word(bytes);
}
private static Byte GenerateRandomByte()
{
Bit[] bits = new Bit[8];
for (int i = 0; i < 8; i++)
{
bits[i] = new Bit(_random.Next(2) == 1);
}
return new Byte(bits);
}
}
}