Added Read/Write function to MC

This commit is contained in:
2026-05-30 22:28:37 -04:00
parent 0be1f139ef
commit 8cf9e2c5f5
20 changed files with 256 additions and 9 deletions
+31 -2
View File
@@ -4,9 +4,38 @@ namespace CPUSimulation
{
public class CPU
{
public void Main(string[] args)
static Random _random = new Random();
static MC _memoryController;
public static void Main(string[] args)
{
Console.WriteLine("Hello, CPU Simulation!");
_memoryController = new MC(8, 2048);
for (int i = 0; i < 2049; i++)
{
Word dataToWrite = GenerateRandomWord(_random.Next(1, 9));
_memoryController.Write(i, dataToWrite);
Word dataRead = _memoryController.Read(i);
Console.WriteLine($"Data read from address {i}: {dataRead.ToString()}");
}
}
private static Word GenerateRandomWord(int byteCount)
{
//Console.WriteLine($"Generating random word with {byteCount} bytes.");
Byte[] bytes = new Byte[byteCount];
for (int i = 0; i < byteCount; i++)
{
bytes[i] = GenerateRandomByte();
}
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);
}
}
}