begin a=4'h3;
$display(\ #100 a=4'h7;
$display(\ #100 a=4'hf;
$display(\ #100 a=4'ha;
$display(\ #100 a=4'h2;
$display(\
#100 $display(\ $stop; end
non_blocking non_blocking(clk,a,b2,c2); blocking blocking(clk,a,b1,c1); endmodule
Î壮×ۺϷÂÕæ½á¹û
ʵÑéÎå ÓÃalways¿éʵÏֽϸ´ÔÓµÄ×éºÏÂß¼£º
Ò»£®ÊµÑéÄ¿µÄ£º
1£®ÕÆÎÕÓÃalwaysʵÏֽϴó×éºÏÂß¼µç·µÄ·½·¨¡£
2£®½øÒ»²½Á˽âassignÓëalwaysÁ½ÖÖ×éºÏµç·ʵÏÖ·½·¨µÄÇø±ðºÍ×¢Òâµã¡£ 3£®Ñ§Ï°²âÊÔÄ£¿éÖÐËæ»úÊýµÄ²úÉúºÍÓ¦Óᣠ4£®Ñ§Ï°×ۺϲ»Í¬²ã´ÎµÄ·ÂÕæ£¬²¢±È½Ï½á¹û ¶þ£®ÊµÑéÉ豸£º
°²×°Modelsim-6.5cµÄPC»ú¡£ Èý£®ÊµÑéÄÚÈÝ£º
Éè¼ÆÒ»¸ö¼òµ¥µÄÖ¸ÁîÒëÂëµç·£¬¸Ãµç·ͨ¹ý¶ÔÖ¸ÁîµÄÅжϣ¬¶ÔÊäÈëÊý¾ÝÖ´ÐÐÏàÓ¦µÄ²Ù×÷£¬°üÀ¨¼Ó¡¢¼õ¡¢Óë¡¢»òºÍÇó·´£¬²¢ÇÒÎÞÂÛÊÇÖ¸Áî×÷ÓõÄÊý¾Ý»¹ÊÇÖ¸Áî±¾Éí·¢Éú±ä»¯£¬¶¼ÓÐÒª×÷³ö¼°Ê±µÄ·´Ó¦¡£
ËÄ£®ÊµÑé´úÂë
`define plus 3'd0
`define minus 3'd1 `define band 3'd2 `define bor 3'd3 `define unegate 3'd4
module alu(out,opcode,a,b); output [7:0]out; reg [7:0]out;
input [2:0]opcode; input [7:0]a,b;
always @(opcode or a or b) begin
case(opcode) `plus: out=a+b; `minus: out=a-b; `band: out=a&b; `bor: out=a|b; `unegate: out=~a;
default: out=8'hx; endcase end endmodule
`timescale 1ns/1ns module alutest; wire [7:0]out; reg [7:0]a,b; reg [2:0]opcode; parameter times=5; initial begin
a={$random}%6; b={$random}%6; opcode=3'h0; repeat(times) begin
#100 a={$random}%6; b={$random}%6; opcode=opcode+1; end
#100 $stop; end
alu alu1(out,opcode,a,b); endmodule
Î壮×ۺϷÂÕæ½á¹û
ʵÑéÁù ÔÚ Verilog HDLÖÐʹÓú¯Êý
Ò»£®ÊµÑéÄ¿µÄ£º
1£®Á˽⺯ÊýµÄ¶¨ÒåºÍÔÚÄ£¿éÉè¼ÆÖеÄʹÓᣠ2£®Á˽⺯ÊýµÄ¿É×ÛºÏÐÔÎÊÌâ¡£
3£®Á˽âÐí¶à×ÛºÏÆ÷²»ÄÜ×ۺϸ´ÔÓµÄËãÊõÔËËã¡£ ¶þ£®ÊµÑéÉ豸£º
°²×°Modelsim-6.5cµÄPC»ú¡£ Èý£®ÊµÑéÄÚÈÝ£º
×öÒ»¸öº¯Êýµ÷ÓõÄʾÀý£¬²ÉÓÃͬ²½Ê±ÖÓ´¥·¢ÔËËãµÄÖ´ÐУ¬Ã¿¸öclkʱÖÓÖÜÆÚÖ´ÐÐÒ»´ÎÔËË㣬ÔÚ²âÊÔÄ£¿éÖУ¬µ÷ÓÃϵͳÈÎÎñ$display¼°ÔÚʱÖÓµÄϽµÑØÏÔʾÿ´ÎÔËËãµÄ½á¹û¡£
ËÄ£®ÊµÑé´úÂë
module tryfunct(clk,n,result,reset); output [31:0]result; input [3:0]n; input reset,clk; reg [31:0]result;
always @(posedge clk) begin
if(!reset) result<=0; else begin
result<=n*factorial(n)/((n*2)+1); end end
function [31:0]factorial; input [3:0]operand; reg [3:0]index; begin
factorial=operand? 1:0;
for(index=2;index<=operand;index=index+1) factorial=index*factorial; end
endfunction