-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.cs
More file actions
33 lines (28 loc) · 909 Bytes
/
Memory.cs
File metadata and controls
33 lines (28 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
namespace NARDIAC
{
public class Memory
{
readonly Word[] storage = new Word[100];
public Memory()
{
storage[0] = new Word(0, 0, 1);
storage[99] = new Word(8, 0, 0);
}
public Word this[int index]
{
get
{
if (index < 0 || index > 99) throw new ArgumentOutOfRangeException(nameof(index));
return storage[index];
}
set
{
if (index < 0 || index > 99) throw new ArgumentOutOfRangeException(nameof(index));
if (index == 0) throw new ArgumentOutOfRangeException(nameof(index));
if (index == 99 && value.Item1 != 8) throw new ArgumentException("The first digit in cell 99 must be an 8", nameof(value));
storage[index] = value;
}
}
}
}