Chapter 3
Sequential Logic
DFF
Data Flip-Flop(primitive):延遲觸發器(或數據觸發器)。是一個基本的狀態保持裝置,是已經寫好的程式因此我們可以直接使用,存儲設備是由在相同的一個時鐘信號前提下許多的flip-flops組成的。我們在使用時可以存儲下來輸出的值。
Bit
1-bit register。通過load(t-1)的值決定out(t)是否改變。
CHIP Bit {
IN in, load;
OUT out;
PARTS:
// Put your code here:
DFF(in = muxout,out = ffout,out = out);
Mux(a = ffout,b = in,sel = load,out = muxout);
}
Register
16-bit register.
CHIP Register {
IN in[16], load;
OUT out[16];
PARTS:
// Put your code here:
Bit(in = in[0],load = load,out = out[0]);
Bit(in = in[1],load = load,out = out[1]);
Bit(in = in[2],load = load,out = out[2]);
Bit(in = in[3],load = load,out = out[3]);
Bit(in = in[4],load = load,out = out[4]);
Bit(in = in[5],load = load,out = out[5]);
Bit(in = in[6],load = load,out = out[6]);
Bit(in = in[7],load = load,out = out[7]);
Bit(in = in[8],load = load,out = out[8]);
Bit(in = in[9],load = load,out = out[9]);
Bit(in = in[10],load = load,out = out[10]);
Bit(in = in[11],load = load,out = out[11]);
Bit(in = in[12],load = load,out = out[12]);
Bit(in = in[13],load = load,out = out[13]);
Bit(in = in[14],load = load,out = out[14]);
Bit(in = in[15],load = load,out = out[15]);
}
RAM8
16-bit/8-register memory.
CHIP RAM8 {
IN in[16], load, address[3];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in = load,sel = address,a = a,b = b,c = c,d = d,e = e,f = f,g = g,h = h);
Register(in = in,load = a,out = outa);
Register(in = in,load = b,out = outb);
Register(in = in,load = c,out = outc);
Register(in = in,load = d,out = outd);
Register(in = in,load = e,out = oute);
Register(in = in,load = f,out = outf);
Register(in = in,load = g,out = outg);
Register(in = in,load = h,out = outh);
Mux8Way16(a = outa,b = outb,c = outc,d = outd,e = oute,f = outf,g = outg,h = outh,sel = address,out = out);
}
RAM64
16-bit/64-register memory.
CHIP RAM64 {
IN in[16], load, address[6];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in = load,sel = address[3..5],a = a,b = b,c = c,d = d,e = e,f = f,g = g,h = h);
RAM8(in = in,load = a,address = address[0..2],out = outa);
RAM8(in = in,load = b,address = address[0..2],out = outb);
RAM8(in = in,load = c,address = address[0..2],out = outc);
RAM8(in = in,load = d,address = address[0..2],out = outd);
RAM8(in = in,load = e,address = address[0..2],out = oute);
RAM8(in = in,load = f,address = address[0..2],out = outf);
RAM8(in = in,load = g,address = address[0..2],out = outg);
RAM8(in = in,load = h,address = address[0..2],out = outh);
Mux8Way16(a = outa,b = outb,c = outc,d = outd,e = oute,f = outf,g = outg,h = outh,sel = address[3..5],out = out);
}
RAM512
16-bit/512-register memory.
CHIP RAM512 {
IN in[16], load, address[9];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in = load,sel = address[6..8],a = a,b = b,c = c,d = d,e = e,f = f,g = g,h = h);
RAM64(in = in,load = a,address = address[0..5],out = outa);
RAM64(in = in,load = b,address = address[0..5],out = outb);
RAM64(in = in,load = c,address = address[0..5],out = outc);
RAM64(in = in,load = d,address = address[0..5],out = outd);
RAM64(in = in,load = e,address = address[0..5],out = oute);
RAM64(in = in,load = f,address = address[0..5],out = outf);
RAM64(in = in,load = g,address = address[0..5],out = outg);
RAM64(in = in,load = h,address = address[0..5],out = outh);
Mux8Way16(a = outa,b = outb,c = outc,d = outd,e = oute,f = outf,g = outg,h = outh,sel = address[6..8],out = out);
}
RAM4K
16-bit/4096-register memory
CHIP RAM4K {
IN in[16], load, address[12];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in = load,sel = address[9..11],a = a,b = b,c = c,d = d,e = e,f = f,g = g,h = h);
RAM512(in = in,load = a,address = address[0..8],out = outa);
RAM512(in = in,load = b,address = address[0..8],out = outb);
RAM512(in = in,load = c,address = address[0..8],out = outc);
RAM512(in = in,load = d,address = address[0..8],out = outd);
RAM512(in = in,load = e,address = address[0..8],out = oute);
RAM512(in = in,load = f,address = address[0..8],out = outf);
RAM512(in = in,load = g,address = address[0..8],out = outg);
RAM512(in = in,load = h,address = address[0..8],out = outh);
Mux8Way16(a = outa,b = outb,c = outc,d = outd,e = oute,f = outf,g = outg,h = outh,sel = address[9..11],out = out);
}
RAM16K
16-bit/16384-register memory
CHIP RAM16K {
IN in[16], load, address[14];
OUT out[16];
PARTS:
// Put your code here:
DMux4Way(in = load,sel = address[12..13],a = a,b = b,c = c,d = d);
RAM4K(in = in,load = a,address = address[0..11],out = outa);
RAM4K(in = in,load = b,address = address[0..11],out = outb);
RAM4K(in = in,load = c,address = address[0..11],out = outc);
RAM4K(in = in,load = d,address = address[0..11],out = outd);
Mux4Way16(a = outa,b = outb,c = outc,d = outd,sel = address[12..13],out = out);
}
RAM anatomy
PC
16-bit program counter.
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
// Put your code here:
Inc16(in = feedback,out = incout);
Mux16(a = feedback,b = incout,sel = inc,out = out1);
Mux16(a = out1,b = in,sel = load,out = out2);
Mux16(a = out2,b = false,sel = reset,out = out3);
Register(in = out3,load = true,out = out,out = feedback);
}