VERILOG 试题样题

  • 格式:pdf
  • 大小:102.89 KB
  • 文档页数:4

VERILOG 试题样题 

1. 程序注释题 (填空题) 

例题1 

module mux21(ina,inb,sel,out); 1)

input ina,inb; 2)

input sel;

output out; 3)

reg out; 4)

assign out= sel? ina , inb; 5)

endmodule 

6)程序的功能是:

例题2 

module count4(out,reset,clk); 1)

input reset,clk; 2)

output reg[3:0] out; 3)

always @(posedge clk) 4)

begin 

if(reset) out<=0; 5)

else out<=out+1; 6)

end

endmodule 

7)程序的功能是:

2. 程序修改题 

例题3 下面程序是Verilog语言设计的D 触发器,请修改程序将其变为同步清零reset(低

电平有效),同步置位set(低电平有效)的D触发器,将完整的程序写在答题纸上,修改后

的模块名字为dff_syn。 

module dff(q,d,clk); 

input d,clk; output reg q; 

always @(posedge clk) 

begin 

q<=d; 

end 

endmodule 

3. 编程题 (根据电路图设计) 

例题4 设计一个4位二进制加法器,模块名字为add4_bin 

 例题5 设计一个程序,实现以下数字电路的功能 

答案 

1. 程序注释题 (填空题) 

例题1 

module mux21(ina,inb,sel,out); 1) 定义模块名

input ina,inb; 2) 定义ina, inb为输入端口

input sel;

output out; 3) 定义out为输出端口

reg out; 4) 定义out 为 reg型

assign out= sel? ina , inb; 5)根据sel的值,选择输出ina 或inb

endmodule 

6)程序的功能是: 2选一的多路选择器

例题2 

module count4(out,reset,clk); 1) 定义模块名

input reset,clk; 2) 定义reset, clk为输入端口

output reg[3:0] out; 3) 定义out为4位宽的reg类型输出端口

always @(posedge clk) 4) clk 上升沿有效

begin 

if(reset) out<=0; 5) 同步复位

else out<=out+1; 6) 输出的数加1

end 

endmodule 

7)程序的功能是: 带同步复位的4位二进制加法计数器 

2. 程序修改题 

例题3

module dff_syn(q,d,clk,set,reset); 

input d,clk,set,reset; output reg q;

 always @(posedge clk) 

begin 

if(~reset)

q<=1'b0;

//同步清0,低电平有效 

else if(~set)

q<=1'b1;

//同步置1,低电平有效 

else

q<=d;

end 

endmodule 

3. 编程题 (根据电路图设计) 

例题4 设计一个4位二进制加法器,模块名字为add4_bin 

module add4_bin(cout,sum,ina,inb,cin); 

input cin; input[3:0] ina,inb; 

output[3:0] sum; output cout; 

assign {cout,sum}=ina+inb+cin; 

endmodule 

例题5 设计一个程序,实现以下数字电路的功能 

module half_add1(a, b, sum, cout); 

input a, b; 

output sum, cout; 

and (cout, a, b); 

xor (sum, a, b); 

endmodule 

或者 

module half_add2(a, b, sum, cout); 

input a, b; 

output sum, cout; 

assign sum = a ^ b;

 assign cout = a & b; 

endmodule 

或者 

module half_add2(a, b, sum, cout); 

input a, b; 

output sum, cout; 

assign {cout, sum} = a + b; 

endmodule