Basic:
第一题:simple wire:
通过添加一条assign语句来连接in和out,从而创建一条线(绿色部分)。
正确答案:
module top_module( input in, output out );
assign out = in;
endmodule
第二题: four wires:
这题看简介有些繁琐,大概意思是:当我们需要多个赋值语句来完成图中的要求时,他们在代码中出现的顺序并不重要。与编程语言不通的事,赋值语句(“连续赋值”)旨在描述事物间的练习,而非将数值复制拷贝的行为。
所以打乱顺序也无妨;相互之间的赋值行为不冲突:
正确答案:
module top_module(
input a,b,c,
output w,x,y,z );
assign w = a;
assign x = b;
assign y = b;
assign z = c;
endmodule
第三题:Notgates
简单的非门:即输出out为输入in的非,应使用~符号;
正确答案:
module top_module( input in, output out );
assign out = ~in;
endmodule
第四题:Andgates
简单与门:即输出out为输入in的与,应使用&符号;
不使用&&,他们两个间的区别是&&为逻辑与,&为二元与,本题只需要使用二元与符号。
正确答案:
module top_module(
input a,
input b,
output out );
assign out = a&b;
endmodule
第五题:Norgates:
或非门:或非的逻辑是或然后再非,由此可得正确答案:
module top_module(
input a,
input b,
output out );
assign out = ~(a|b);
endmodule
第六题:Xnorgates:
同或:相同为1,相异为0;同或是异或的相反情况,异或符号为^,所以同或为~(a^b);
正确答案:
module top_module(
input a,
input b,
output out );
assign out = ~(a^b);
endmodule
第七题:Wire decl:
声明用的wire:
随着电路的复杂化,有时需要使用wire来方便变量间的连接。这道题就是需要我们使用wire语句解决问题:
正确答案:
`default_nettype none
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire w1,w2;
assign w1 = a&b;
assign w2 = c&d;
assign out = w1|w2;
assign out_n = ~out;
endmodule
第八题:7458
7458是一个具有四个与门和两个或门的芯片。可以使用上题的wire语句声明一些量以完成该问题。初学者可能会有点乱,仔细分析就能看出,只有四根导线不是直接连接输入或输出的,此时就需要我们使用wire语句来连接输入/输出:
正确答案:
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
wire a,b,c,d;
assign a = p2a&p2b;
assign b = p2c&p2d;
assign c = p1c&p1a&p1b;
assign d = p1e&p1f&p1d;
assign p1y = c|d;
assign p2y = a|b;
endmodule
使用wire语句声明、使用assign语句赋值。