PageRenderTime 41ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

/3/1/RAM8.hdl

http://github.com/happy4crazy/elements_of_computing_systems
Unknown | 56 lines | 49 code | 7 blank | 0 comment | 0 complexity | ada908ff086e844353380e70873abc43 MD5 | raw file
 1// This file is part of the materials accompanying the book 
 2// "The Elements of Computing Systems" by Nisan and Schocken, 
 3// MIT Press. Book site: www.idc.ac.il/tecs
 4// File name: projects/03/1/RAM8.hdl
 5
 6/**
 7 * Memory of 8 registers, each 16-bit wide.  
 8 * The chip facilitates read and write operations, as follows:
 9 *     Read:  out(t) = RAM8[address(t)](t)
10 *     Write: If load(t-1) then RAM8[address(t-1)](t) = in(t-1)
11 * In words: the chip always outputs the value stored at the memory 
12 * location specified by address. If load=1, the in value is loaded 
13 * into the memory location specified by address.  This value becomes 
14 * available through the out output starting from the next time step.
15 */
16
17CHIP RAM8 {
18
19    IN  in[16], load, address[3];
20    OUT out[16];
21
22    PARTS:
23    
24    // first, demux the load bit out to each of the registers
25    // the idea is that if load=0, then every register sees load=0
26    // but if load=1, only the address register sees load=1
27    DMux8Way(in=load, sel=address,
28             a=load0,
29             b=load1,
30             c=load2,
31             d=load3,
32             e=load4,
33             f=load5,
34             g=load6,
35             h=load7);
36
37    Register(in=in, load=load0, out=out0);
38    Register(in=in, load=load1, out=out1);
39    Register(in=in, load=load2, out=out2);
40    Register(in=in, load=load3, out=out3);
41    Register(in=in, load=load4, out=out4);
42    Register(in=in, load=load5, out=out5);
43    Register(in=in, load=load6, out=out6);
44    Register(in=in, load=load7, out=out7);
45
46    // Now we just need to mux the register outputs according to address
47    Mux8Way16(a=out0,
48              b=out1,
49              c=out2,
50              d=out3,
51              e=out4,
52              f=out5,
53              g=out6,
54              h=out7,
55              sel=address, out=out);
56}