Added Read/Write function to MC
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user