题解 | #4bit超前进位加法器电路#

4bit超前进位加法器电路

http://www.nowcoder.com/practice/4d5b6dc4bb2848039da2ee40f9738363

使用动态生成语句:generate—for,实现重复例化;

`timescale 1ns/1ns

module lca_4(
	input		[3:0]       A_in  ,
	input	    [3:0]		B_in  ,
    input                   C_1   ,
 
 	output	 wire			CO    ,
	output   wire [3:0]	    S
);
    wire [3:0] g, p;
    wire [3:0] c_temp, pc_temp;
    genvar i;
    generate
        for(i=0;i<4;i=i+1)
            begin:some
                xor p_gate (p[i], A_in[i], B_in[i]);
                and g_gate (g[i], A_in[i], B_in[i]);
                
                if(i == 0) begin
                    and pc_gate (pc_temp[i], p[i], C_1);
                    xor s_gate (S[i], p[i], C_1);
                end
                else begin
                    and pc_gate (pc_temp[i], p[i], c_temp[i-1]);
                    xor s_gate (S[i], p[i], c_temp[i-1]);
                end
                
                or c_gate (c_temp[i], g[i], pc_temp[i]);
                
            end
    endgenerate
    
    assign CO = c_temp[3];
    
endmodule
全部评论
begin后的some是干啥的?
1 回复 分享
发布于 2022-04-11 15:42
为什么 “or c_gate (c_temp[i], g[i], pc_temp[i]);”这一句不能放在if里面?我把它和0<4部分写在一起后无法生成S。
点赞 回复 分享
发布于 2022-04-19 12:07

相关推荐

二十岁的编程男神王大...:读博吧兄弟,你这绩点太好了,何必转码,另外哈哈哈真见到有括号标出来985的,这个不标注也知道吧
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
23
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务