Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verilog why is [NumberOfBits-1:0] and what is it actually doing

Tags:

bit

verilog

I'm trying to learn Verilog but in the example I'm studying the [NumberOfBits-1:0] command is used and I can't quite figure out why it's there and what it's doing. Here's my code:

module verilogmodule(Minuend,Subtrahend,SumDiff,CarryOut,Mode);
//4-bit adder and subtractor. Mode=0 to add and Mode = 1 to subtract
parameter NumberOfBits = 4;
input [NumberOfBits-1:0] Minuend, Subtrahend; input Mode;
output [NumberOfBits-1:0] SumDiff; output CarryOut;

wire [NumberOfBits-1:0] InverterOut;
wire [NumberOfBits-1:0] MuxOut;
wire [NumberOfBits-1:0] AdderLowCarryout;

//module not4bits(A3,A2,A1,A0,Y3,Y2,Y1,Y0);
not4bits U1 (Subtrahend[3], Subtrahend[2], Subtrahend[1], Subtrahend[0],InverterOut[3], InverterOut[2], InverterOut[1],InverterOut[0]);
 //module mux4bits(A,B,Y,choice);
 mux4bits U2(Subtrahend,InverterOut,MuxOut,Mode);
 //module adder2bits(A,B,Cin, Sum, Cout);
adder2bits AdderLow(Minuend[1:0],MuxOut[1:0],Mode,SumDiff[1:0],AdderLowCarryout[1:0]);
adder2bits AdderHigh(Minuend[3:2],MuxOut[3:2],AdderLowCarryout[1:0],SumDiff[3:2],CarryOut);


endmodule
like image 752
Fdsa Fdsa Avatar asked Nov 22 '25 11:11

Fdsa Fdsa


1 Answers

That's not a command, it's the width of the wire.

For example here:

wire [NumberOfBits-1:0] MuxOut;

NumberOfBits is a parameter of value 4, so after substitution the wire width becomes [4-1:0], or [3:0]. This just means a wire of width 4, with individual bits of 3, 2, 1, and 0.

like image 143
Tim Avatar answered Nov 25 '25 06:11

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!