第三节了加加

//模块实例化
/*掌握的知识点
1:实例化:当引用一个写好的模块,实例化时;有两种方法
按位置:模块名 例化的名字(信号名1,信号名2.......)
按名称:模块名 例化的名字(.信号名1(对应的信号1),.信号名2(对应的信号2).......)



*/




//1.
module top_module ( input a, input b, output out );

mod_a u_m( a,b,out);
endmodule

//2.
module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);
     mod_a u_m( out1, out2, a, b, c, d );

endmodule
//3.
module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);
    mod_a u_m( .out1(out1), .out2(out2),.in1(a),.in2(b),.in3(c),.in4(d));
endmodule
//4. 长度为3的移位寄存器
module top_module ( input clk, input d, output q );
    reg q1,q2;
    my_dff u1( clk,d,q1 );
    my_dff u2( clk,q1,q2 );
    my_dff u3( clk,q2,q );
endmodule
//5.  实现三个8位的D触发器串联起来,再创建一个4选1多路复用器,根据输入选择延长的周期数
module top_module ( 
    input clk, 
    input [7:0] d, 
    input [1:0] sel, 
    output [7:0] q 
);
    reg [7:0] q1,q2,q3;
    my_dff8 u1( clk, d,q1 );
    my_dff8 u2( clk, q1,q2 );
    my_dff8 u3( clk, q2,q3 );
    always@(*)begin
        case (sel)
            2'd0:q=d;
            2'd1:q=q1;
            2'd2:q=q2;
            2'd3:q=q3;
            default:;
        endcase
    end
endmodule
//6.您将获得一个执行 16 位加法的模块。实例化其中两个以创建一个 32 位加法器。一个 add16 模块计算加法结果的下限 16 位,而第二个 add16 模块在从第一个加法器接收到执行后计算结果的上部 16 位。您的 32 位加法器不需要处理携带(假设 0)或执行(忽略),但内部模块需要处理才能正常工作。(换句话说,模块执行 16 位 a + b + cin,而模块执行 32 位 a + b)。
module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    
    wire cin,cout;
    add16 u1( a[15:0], b[15:0],0,sum[15:0],cin );
    add16 u2( a[31:16], b[31:16],cin,sum[31:16],cout );
endmodule
//6.
module top_module (
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
//7.
    
    wire	cout;
    
    add16 u1_add16(
        .a      (a[15:0]	),
        .b      (b[15:0]	),
        .cin	(1'b0		),
        .sum	(sum[15:0]	),
        .cout	(cout		)
    );
    add16 u2_add16(
        .a      (a[31:16]	),
        .b      (b[31:16]	),
        .cin	(cout		),
        .sum	(sum[31:16]	),
        .cout	(        	)
    );
    
endmodule
 
module add1 ( input a, input b, input cin,   output sum, output cout );
    
    assign {cout, sum} = a + b + cin;
    
endmodule
//8.
module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    
    wire[15:0]	sum_1;
    wire[15:0]	sum_2;
    wire[15:0]	sum_3;
    wire        cout;
    
    assign sum = cout ? {sum_3, sum_1} : {sum_2, sum_1};
    
    add16 u1_add16(
        .a      (a[15:0]    ),
        .b      (b[15:0]    ),
        .cin	(1'b0	    ),
        .sum	(sum_1	    ),
        .cout   (cout       )
    );
    
    add16 u2_add16(
        .a      (a[31:16]   ),
        .b      (b[31:16]   ),
        .cin	(1'b0       ),
        .sum	(sum_2      ),
        .cout	(           )
    );
    add16 u3_add16(
        .a      (a[31:16]   ),
        .b      (b[31:16]   ),
        .cin	(1'b1	    ),
        .sum	(sum_3	    ),
        .cout	(           )
    );
 
endmodule
//9.
module top_module(
    input [31:0] a,
    input [31:0] b,
    input sub,
    output [31:0] sum
);
    wire cout,cout1;
    wire [31:0]b1;
    assign b1 = {32{sub}}^b;
    add16 u1(  a[15:0],  b1[15:0], sub,  sum[15:0], cout );
    add16 u2(  a[31:16], b1[31:16], cout, sum[31:16],cout1  );
endmodule


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值