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.
This commit is contained in:
@@ -133,11 +133,24 @@ namespace CPUSimulation
|
||||
return addressString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A word is a collection of 2 Bytes
|
||||
/// </summary>
|
||||
public class Word
|
||||
{
|
||||
Byte[] _bytes;
|
||||
public Word(Byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0 || bytes.Length > 2)
|
||||
{
|
||||
throw new ArgumentException("A word must consist of 1 or 2 bytes.");
|
||||
}
|
||||
else if (bytes.Length == 1)
|
||||
{
|
||||
_bytes = new Byte[2] { new Byte("00000000"), bytes[0] };
|
||||
}
|
||||
_bytes = bytes;
|
||||
}
|
||||
|
||||
@@ -164,4 +177,42 @@ namespace CPUSimulation
|
||||
return wordString;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A double word is a collection of 2 Words, or 4 Bytes
|
||||
/// </summary>
|
||||
public class DWord
|
||||
{
|
||||
Word _highWord;
|
||||
Word _lowWord;
|
||||
public DWord(Word highWord, Word lowWord)
|
||||
{
|
||||
_highWord = highWord;
|
||||
_lowWord = lowWord;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _highWord.ToString() + _lowWord.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A quad word is a collection of 2 Double Words, or 8 Bytes
|
||||
/// </summary>
|
||||
public class QWord
|
||||
{
|
||||
DWord _highDWord;
|
||||
DWord _lowDWord;
|
||||
public QWord(DWord highDWord, DWord lowDWord)
|
||||
{
|
||||
_highDWord = highDWord;
|
||||
_lowDWord = lowDWord;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return _highDWord.ToString() + _lowDWord.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user