- 1、本文档共2页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Verilogexamples.PDF
Verilog examples
//*************************************************// // 来自:《Verilog,HDL程序设计教程》by王金明 //
备注:以下程序尚未进行验证 //*************************************************////4位全加器 module
adder4(sum, cout, ina, inb, cin); output[3:0] sum; output cout; input[3:0] ina, inb; input cin; assign
{cout, sum} = ina + inb + cin; endmodule//4位计数器 module counter4(out, reset, clk); output[3:0] out;
input reset, clk; reg[3:0] out; always @(posedge clk) begin if(reset) out = 0; else out = out + 1; end
endmodule//4位全加器的仿真程序 `timescale 1ns/1ns `include adder4.v module adder4_testbench; reg[3:0]
a, b; reg cin; wire[3:0] sum; wire cout; integer i, j;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 a = i; endinitial begin
for(j = 1; j 16; j = j + 1) #10 b = j; endinitial begin $monitor($time,,,%d + %d + %b = {%b, %d}, a,
b, cin, cout, sum); #160 $finish; end endmodule//4位计数器的仿真程序 `timescale 1ns/1ns `include
counter4.v module counter4_testbench; reg clk, reset; wire[3:0] out; parameter DELAY = 100;counter4
mycount(out, reset, clk);always #(DELAY/2) clk = ~clk;initial begin clk = 0; reset = 0; #DELAY reset =
1; #DELAY reset = 0; #(DELAY*20) $finish endinitial $monitor($time,,,clk=%d reset=%d out=%d, clk,
reset, out); endmodule//“与-或-非”门电路 module AOI(F, A, B, C, D); output F; input A, B, C, D; wire
A, B, C, D, F; assign F = ~((AB)|(CD)); endmodule//用case语句描述的4选1数据选择器 module mux4_1(out,
in0, in1, in2, in3, sel); output out; input in0, in1, in2, in3; input[1:0]; reg out; always @(in0 or in1
or in2 or in3 or sel) case(sel) 2b00: out = in0; 2b01: out = in1; 2b10: out = in2; 2b11: out = in3;
default: out = 2bx; endcase endmodule//同步置数、同步清零的计数器 module count(out, data, load, reset,
clk); output[7:0] out; input[7:0] data; input load, reset, clk; reg[7:0] out; always @(posedge clk)
begin if(reset) out = 8h00; else if(load) out = data; e
文档评论(0)