【verilog HDL】

Verilog HDL刷题记录1:Module addsub

An adder-subtractor can be built from an adder by optionally negating one of the inputs, which is equivalent to inverting the input then adding 1. The net result is a circuit that can do two operations: (a + b + 0) and (a + ~b + 1). See Wikipedia if you want a more detailed explanation of how this circuit works.
Build the adder-subtractor below.
You are provided with a 16-bit adder module, which you need to instantiate twice:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
Use a 32-bit wide XOR gate to invert the b input whenever sub is 1. (This can also be viewed as b[31:0] XORed with sub replicated 32 times. See replication operator.). Also connect the sub input to the carry-in of the adder.
注: 这里的意思是,根据输入sub的值来决定是否对b进行异或操作。
在这里插入图片描述

module top_module(
    input [31:0] a,
    input [31:0] b,
    input sub,
    output [31:0] sum
);
    wire carry;
    wire [31:0] bx = sub?b^{32{sub}}:b;
    add16 add16_ins1(a[15:0],bx[15:0],sub,sum[15:0],carry);
    add16 add16_ins2(a[31:16],bx[31:16],carry,sum[31:16]);
endmodule
  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Verilog HDL (Hardware Description Language) is a high-level hardware description language used to model, simulate, and synthesize digital circuits and systems. It is commonly used in the design of digital electronic systems, such as microprocessors, digital signal processors, and other digital circuits. Verilog HDL provides a powerful set of constructs to describe the behavior and structure of digital circuits. It allows designers to describe the functionality of a circuit in terms of logical operations, timing constraints, and other parameters. Verilog HDL is widely used in the design of integrated circuits and other digital systems. It is supported by most modern EDA (Electronic Design Automation) tools and is used by designers to create complex digital circuits and systems. Some of the key features of Verilog HDL include: 1. Hierarchical modeling: Verilog HDL supports hierarchical modeling, which allows designers to build complex systems by combining smaller building blocks. 2. Behavioral modeling: Verilog HDL supports behavioral modeling, which allows designers to describe the functionality of a circuit in terms of logical operations and other parameters. 3. Structural modeling: Verilog HDL supports structural modeling, which allows designers to describe the physical structure of a circuit. 4. Timing modeling: Verilog HDL supports timing modeling, which allows designers to specify timing constraints and other parameters that affect the behavior of a circuit. Overall, Verilog HDL is a powerful tool for designing and simulating digital circuits and systems. It is widely used in the electronics industry and is an essential skill for anyone working in digital design.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值