资料介绍
examples王金明: 《 Verilog HDL 程序设计教程》
【例 3.1】4 位全加器
module adder4(cout,sum,ina,inb,cin); output[3:0] sum; output cout; input[3:0] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule
【例 3.2】4 位计数器
module count4(out,reset,clk); output[3:0] out; input reset,clk; reg[3:0] out; always @(posedge clk) begin if (reset) else end endmodule out<=0; out<=out+1; //同步复位 //计数
【例 3.3】4 位全加器的仿真程序
`timescale 1ns/1ns `include "adder4.v" module adder_tp; reg[3:0] a,b; reg cin; wire[3:0] sum; wire cout; integer i,j; //调用测试对象 //设定 cin 的取值 //测试输出信号定义为 wire 型 //测试模块的名字 //测试输入信号定义为 reg 型
adder4 adder(sum,cout,a,b,cin); always #5 cin=~cin;
initial begin a=0;b=0;cin=0; for(i=1;i<16;i=i+1) #10 end a=i; //设定 a 的取值
-1 -
程序文本
initial begin for(j=1;j<16;j=j+1) #10 end //定义结果显示格式 b=j; //设定 b 的取值
initial begin
$mo