这一章的关键词:
*时钟 触发器 寄存器 内存
时钟:
让一切的行走定于同一基准,其精准的硬件实现通常在于振荡器,其在两个信号值“0-1”,或称“低电平—高电平”之间交替变化。两个相邻上升沿之间的时间间隙称谓时钟的周期。
触发器:(主要是利用DFF或D触发器为基准构建一切)
简单点将前一个时间周期的输入值作为当前周期的输出。
寄存器:
触发器与第一章 中的多路转换器结合。
内存:
RAM随机存储器,不管物理位置如何,都能以相等的速度被直接访问。
计数器:
每经过一个时间周期,该整数就增加1个单位。典型的CPU包括一个程序计数器,它的输出就是当前程序中下一步将要执行的指令地址。
项目:
1. 1比特位寄存器
/**
* 1-bit register:
* If load[t] == 1 then out[t+1] = in[t]
* else out does not change (out[t+1] = out[t])
*/
CHIP Bit {
IN in, load;
OUT out;
PARTS:
Mux(a=out1,b=in,sel=load,out=out2);//load
=0,READ,load=1,write
DFF(in=out2,out=out1);//保存上次的值
And(a=out1,b=true,out=out);
}
2.Register
//16位寄存器的读写
CHIP Register {
IN in[16], load;
OUT out[16];
PARTS:
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]);
}
3.RAM8
//含有8个16位寄存器
CHIP RAM8 {
IN in[16], load, address[3];
OUT out[16];
PARTS:
DMux8Way(in=load,sel=address,a=a1,b=b1,c=c1,d=d1,e=e1,f=f1,g=g1,h=h1);
Register(in=in,load=a1,out=out1);
Register(in=in,load=b1,out=out2);
Register(in=in,load=c1,out=out3);
Register(in=in,load=d1,out=out4);
Register(in=in,load=e1,out=out5);
Register(in=in,load=f1,out=out6);
Register(in=in,load=g1,out=out7);
Register(in=in,load=h1,out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel=address,out=out);
}
4.RAM64
CHIP RAM64 {
IN in[16], load, address[6];
OUT out[16];
PARTS:
DMux8Way(in=load,sel=address[3..5],a=a1,b=b1,c=c1,d=d1,e=e1,f=f1,g=g1,h=h1);
RAM8(in=in,load=a1,address=address[0..2],out=out1);
RAM8(in=in,load=b1,address=address[0..2],out=out2);
RAM8(in=in,load=c1,address=address[0..2],out=out3);
RAM8(in=in,load=d1,address=address[0..2],out=out4);
RAM8(in=in,load=e1,address=address[0..2],out=out5);
RAM8(in=in,load=f1,address=address[0..2],out=out6);
RAM8(in=in,load=g1,address=address[0..2],out=out7);
RAM8(in=in,load=h1,address=address[0..2],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel=address[3..5],out=out);
}
5 .RAM512
CHIP RAM64 {
IN in[16], load, address[6];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel=address[3..5],a=a1,b=b1,c=c1,d=d1,e=e1,f=f1,g=g1,h=h1);
RAM8(in=in,load=a1,address=address[0..2],out=out1);
RAM8(in=in,load=b1,address=address[0..2],out=out2);
RAM8(in=in,load=c1,address=address[0..2],out=out3);
RAM8(in=in,load=d1,address=address[0..2],out=out4);
RAM8(in=in,load=e1,address=address[0..2],out=out5);
RAM8(in=in,load=f1,address=address[0..2],out=out6);
RAM8(in=in,load=g1,address=address[0..2],out=out7);
RAM8(in=in,load=h1,address=address[0..2],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel=address[3..5],out=out);
}
6.RAM4K
CHIP RAM4K {
IN in[16], load, address[12];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel=address[9..11],a=a1,b=b1,c=c1,d=d1,e=e1,f=f1,g=g1,h=h1);
RAM512(in=in,load=a1,address=address[0..8],out=out1);
RAM512(in=in,load=b1,address=address[0..8],out=out2);
RAM512(in=in,load=c1,address=address[0..8],out=out3);
RAM512(in=in,load=d1,address=address[0..8],out=out4);
RAM512(in=in,load=e1,address=address[0..8],out=out5);
RAM512(in=in,load=f1,address=address[0..8],out=out6);
RAM512(in=in,load=g1,address=address[0..8],out=out7);
RAM512(in=in,load=h1,address=address[0..8],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel=address[9..11],out=out);
}
7.RAM16K
CHIP RAM16K {
IN in[16], load, address[14];
OUT out[16];
PARTS:
DMux4Way(in=load,sel=address[12..13],a=a1,b=b1,c=c1,d=d1);
RAM4K(in=in,load=a1,address=address[0..11],out=out1);
RAM4K(in=in,load=b1,address=address[0..11],out=out2);
RAM4K(in=in,load=c1,address=address[0..11],out=out3);
RAM4K(in=in,load=d1,address=address[0..11],out=out4);
Mux4Way16(a=out1,b=out2,c=out3,d=out4,sel=address[12..13],out=out);
}
8.PC计数器
/**
* A 16-bit counter with load and reset control bits.
* if (reset[t] == 1) out[t+1] = 0
* else if (load[t] == 1) out[t+1] = in[t]
* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
* else out[t+1] = out[t]
*/
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
Mux16(a=back,b=in,sel=load,out=in1);
Mux16(a=in1,b=false,sel=reset,out=in2);
Register(in=in2,load=true,out=out1);
And16(a=out1,b=true,out=out);
Inc16(in=out1,out=out2);
Mux16(a=out1,b=out2,sel=inc,out=back);
}