1.boolean logic
常用的boolean logic有AND OR NOT,其性质如下
事实上,可用AND和NOT来表示OR
x or y = NOT(NOT(x) AND NOT(y))
但没法只用AND或NOT,于是出来了NAND,x NAND y = NOT(x AND y),其真值表如下
于是可以用NAND表示AND和NOT
NOT(x) = x NAND x
x AND y = NOT(x NAND y)
2. HDL逻辑门接口
3.HDL实现
1)Mux4Way16
/**
* 4-way 16-bit multiplexor:
* out = a if sel == 00
* b if sel == 01
* c if sel == 10
* d if sel == 11
*/
自己做的时候超级傻逼。我就想啊,首先用 And(a = sel[0],b = sel[1],out = outd);这样就能通过outd是否为1判断是否选择d,然后把16个元素依次通过And(a = d[0],b = outd,out = out4[0])得到4个长度为16的输出,再把他们相加就得到了最后的输出,超级麻烦超级傻逼。
然后偷偷瞄了下答案,真是哭了,充分利用二进制的结构特性,先看sel[0]来决定用a还是b 或者 c还是d 得到两个备选,再看sel[1]来决定用最后输出,就两行,真是惊呆...
CHIP Mux4Way16 { ], b[], c[], d[], sel[]; ]; PARTS: // Put your code here: Mux16(a = a,b = b,sel = sel[],out = out1); Mux16(a = c,b = d,sel = sel[],out = out2); Mux16(a = out1,b = out2,sel = sel[],out = out); }
2)DMux4Way
哈哈这个题做得好搞,完全不动脑型,把Mux的思路逆着来就行
CHIP DMux4Way { ]; OUT a, b, c, d; PARTS: // Put your code here: DMux(],a = out1,b = out2); DMux(],a = a,b = b); DMux(],a = c,b = d); }