首页 > 其他 > 详细

Answers For HDLbits - Verilog Language_Module_Hierarchy

时间:2021-01-16 21:49:58      阅读:20      评论:0      收藏:0      [点我收藏+]

先上链接https://hdlbits.01xz.net/wiki/Module

 

(1)Module

module top_module ( input a, input b, output out );
    mod_a mod_a1(.in1(a),.in2(b),.out(out));
endmodule

 

(2)Module pos

module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);
    mod_a (out1,out2,a,b,c,d);
endmodule

 

(3)Module name

module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);
    mod_a mod_at(.in1(a),.in2(b),.in3(c),.in4(d),.out1(out1),.out2(out2));
endmodule

 

(4)Module shift

 

module top_module ( input clk, input d, output q );
	wire q1,q2;
    my_dff dff1(
        .clk(clk),
        .d(d),
        .q(q1));
    my_dff dff2(
        .clk(clk),
        .d(q1),
        .q(q2));
	my_dff dff3(
        .clk(clk),
        .d(q2),
        .q(q));
endmodule

 

(5)Module shift8

module top_module ( 
    input clk, 
    input [7:0] d, 
    input [1:0] sel, 
    output [7:0] q 
);
    wire [7:0] q1,q2,q3;
    my_dff8 dff81(clk,d,q1);
    my_dff8 dff82(clk,q1,q2);
    my_dff8 dff83(clk,q2,q3);
    always @(*)
        case(sel)
            2‘b 00 : q = d;
            2‘b 01 : q = q1;
            2‘b 10 : q = q2;
            2‘b 11 : q = q3;
        endcase
    
endmodule

 

(6)Module add

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire cout;
    add16 low16 (a[15:0],b[15:0],1‘b0,sum[15:0],cout);
    add16 high16 (a[31:16],b[31:16],cout,sum[31:16],);
endmodule

 

(7)Module fadd

module top_module (
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);//
    wire cout;
    add16 low16(a[15:0],b[15:0],1‘b0,sum[15:0],cout);
    add16 high16(a[31:16],b[31:16],cout,sum[31:16],);
endmodule

module add1 ( input a, input b, input cin,   output sum, output cout );

// Full adder module here
    assign sum  = a^b^cin;
    assign cout = (a&b)|(a&cin)|(b&cin);
endmodule

 这道题有些误导,系统没有把add16写出来,但题目说已经提供,所以不必写add16的rtl,直接例化add16来用,并表达add1即可。

 

(8)Module cseladd

 

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire cout;
    wire [15:0]sum_0;
    wire [15:0]sum_1;
    add16 low16		(a[15:0],b[15:0],1‘b0,sum[15:0],cout);
    add16 high16_0	(a[31:16],b[31:16],1‘b0,sum_0,);
    add16 high16_1	(a[31:16],b[31:16],1‘b1,sum_1,);
    always @(*)
        case (cout)
            1‘b0 : sum[31:16] = sum_0;
            1‘b1 : sum[31:16] = sum_1;
        endcase
endmodule

 

(9)Module addsub

module top_module(
    input [31:0] a,
    input [31:0] b,
    input sub,
    output [31:0] sum
);
    wire cout;
    wire [31:0]sub_b;
    assign sub_b = {32{sub}}^b;
    add16 low16	(a[15:0],sub_b[15:0],sub,sum[15:0],cout);
    add16 high16(a[31:16],sub_b[31:16],cout,sum[31:16],);
endmodule

 

Answers For HDLbits - Verilog Language_Module_Hierarchy

原文:https://www.cnblogs.com/Bain-M/p/14286641.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!