用generate for循环描述8位级联减法器&集成移位寄存器74161

  1. 用generate for循环描述8位级联减法器
    另外两个输入xi、yi
    全减器输入来自低位的借位Bi(Borrowinput)
    输出为Di和向高位借位Bo。

Di = Xi xor Y xor Bi
Bo=Xi’Yi’Bi+Xi’YiBi’+Xi’YiBi+XiYiBi
=(XiYi +Xi’Yi’)Bi + Xi’Yi
=Xi’Bi+Xi’Yi+YiBi
在这里插入图片描述

module subtractor_8bit(
    input [7:0] X, // 8-bit input X
    input [7:0] Y, // 8-bit input Y
    input B0,      // initial borrow in
    output [7:0] D, // 8-bit output difference
    output B_out    // final borrow out
);
    wire [8:0] B; // Internal borrow wires including B[0] as initial borrow in

    assign B[0] = B0; // assign initial borrow input to B[0]

    genvar i;
    generate
        for (i = 0; i < 8; i = i + 1) begin : full_subtractor
            // Implement the full subtractor logic for each bit
            assign D[i] = X[i] ^ Y[i] ^ B[i]; // Difference bit
            assign B[i+1] = (~X[i] & Y[i]) | (~X[i] & B[i]) | (Y[i] & B[i]); // Borrow out
        end
    endgenerate

    assign B_out = B[8]; // assign the final borrow to B_out

endmodule

2.集成移位寄存器74161

清零预置使能时钟预置数据输入输 出
CLRNLDNENPENTCLKABCDQAQBQCQD
L××××××X×LLLL
HL××ABCDABCD
HHL×××X××保持
HH×L×××××保持
HHHH××××保持
module counter_74161 (
  input wire CLRN, // Asynchronous clear
  input wire LDN,  // Load enable
  input wire ENP,  // Enable parallel count
  input wire ENT,  // Enable toggle
  input wire CLK,  // Clock
  input wire [3:0] D, // Parallel data input
  output reg [3:0] Q // Output
);

always @(posedge CLK or negedge CLRN) begin
  if (!CLRN) begin
    Q <= 4'b0000; // Clear the counter
  end else if (!LDN) begin
    Q <= D; // Load the input data into the counter
  end else if (ENP && ENT) begin
    Q <= Q + 1; // Increment the counter if enabled
  end
  // When ENP or ENT is low, the counter holds its value, so no action is needed
end

endmodule
  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值