45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
|
|
namespace CPUSimulation
|
|
{
|
|
public class CPU
|
|
{
|
|
static Random _random = new Random();
|
|
static MC _memoryController;
|
|
public static void Main(string[] args)
|
|
{
|
|
_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);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|