-
Notifications
You must be signed in to change notification settings - Fork 11
/
RAM512.js
151 lines (140 loc) · 2.9 KB
/
RAM512.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* The MIT License (MIT)
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
'use strict';
const colors = require('colors');
const RAM = require('./RAM');
const {int16Table} = require('../../../util/numbers');
/**
* Canonical truth table for the `RAM512` gate.
*/
const TRUTH_TABLE = int16Table([
{
$clock: -0,
in: 0b0000000000000000,
load: 0,
address: 0,
out: 0b0000000000000000,
},
{
$clock: +0,
in: 0b0000000000010101,
load: 1,
address: 0,
out: 0b0000000000000000,
},
{
$clock: -1,
in: 0b0000000000000001,
load: 0,
address: 0,
out: 0b0000000000010101,
},
{
$clock: +1,
in: 0b0000000000010101,
load: 0,
address: 0,
out: 0b0000000000010101,
},
{
$clock: -2,
in: 0b0000000000010101,
load: 0,
address: 0,
out: 0b0000000000010101,
},
{
$clock: +2,
in: 0b1101001000010101,
load: 1,
address: 2,
out: 0b0000000000000000,
},
{
$clock: -3,
in: 0b1101001000010101,
load: 0,
address: 2,
out: 0b1101001000010101,
},
{
$clock: +3,
in: 0b1111111111111111,
load: 1,
address: 511,
out: 0b0000000000000000,
},
{
$clock: -4,
in: 0b0000000000000000,
load: 1,
address: 511,
out: 0b1111111111111111,
},
{
$clock: +4,
in: 0b0000000000000000,
load: 1,
address: 511,
out: 0b1111111111111111,
},
{
$clock: -5,
in: 0b0000000000000000,
load: 0,
address: 511,
out: 0b0000000000000000,
},
]);
/**
* RAM chip of 512 16-bit registers.
*
* The output is the value stored at the memory location specified by address.
* If load=1, loads the input into the memory location specified by address.
*
* Abstract:
*
* IN in[16], load, address[9];
* OUT out[16];
*
* DMux8Way(in=load, sel=address, ...);
* RAM64(in=in, load=l1, address=address[0..5], out=r1);
RAM64(in=in, load=l2, address=address[0..5], out=r2);
* ...
* Mux8Way16(...);
*/
class RAM512 extends RAM {
constructor(options) {
super(Object.assign({size: 512}, options));
}
}
/**
* Specification of the `RAM512` gate.
*/
RAM512.Spec = {
name: 'RAM512',
description: [
'Memory chip consisting of 512 16-bit registers.',
'',
'If load[t]=1 then out[t+1] = in[t] else out does not change.',
'',
'Clock rising edge updates the value from the input by the address,',
'if the `load` is set; otherwise, preserves the state.',
'',
` ${colors.bold('↗')} : value[address] = load ? in : value[address]`,
'',
'Clock falling edge propagates the value at the address to the output:',
'',
` ${colors.bold('↘')} : out = value[address]`,
].join('\n'),
inputPins: [
{name: 'in', size: 16},
{name: 'load', size: 1},
{name: 'address', size: 9},
],
outputPins: [{name: 'out', size: 16}],
truthTable: TRUTH_TABLE,
};
module.exports = RAM512;