Concept Flow - Bit vectors and bus declaration
Start
Declare bit vector
Assign values to bits
Use vector in logic
Access individual bits
End
This flow shows how a bit vector (bus) is declared, assigned, and used step-by-step in Verilog.
reg [3:0] bus; initial begin bus = 4'b1010; $display("bus = %b", bus); $display("bit 2 = %b", bus[2]); end
| Step | Action | bus value | Accessed bit | Output |
|---|---|---|---|---|
| 1 | Declare bus as 4 bits | xxxx | - | - |
| 2 | Assign bus = 4'b1010 | 1010 | - | - |
| 3 | Display bus | 1010 | - | bus = 1010 |
| 4 | Display bus[2] | 1010 | 1 | bit 2 = 1 |
| 5 | End of initial block | 1010 | - | - |
| Variable | Start | After 2 | Final |
|---|---|---|---|
| bus | xxxx | 1010 | 1010 |
| bus[2] | - | 1 | 1 |
Bit vectors (buses) are declared with [msb:lsb], e.g., reg [3:0] bus; Each bit can be accessed by bus[index], index 0 is least significant bit. Before assignment, bits are undefined (x). Assign values using binary notation like 4'b1010. Use $display to print bus or individual bits.
wire [7:0] data_bus; represent in Verilog?[7:0] means a vector from bit 7 down to bit 0, so 8 bits total.wire [7:0] data_bus; creates a wire signal that is 8 bits wide, indexed 7 to 0.reg16 in Verilog?reg [width] name;.reg [15:0] reg16;. reg reg16[15:0]; uses array syntax incorrectly. reg16 reg [15:0]; has incorrect order of keywords. reg [0:15] reg16; uses a reversed bit range, which is allowed but less common and can cause confusion.wire [3:0] bus; assign bus = 4'b1010; wire bit0 = bus[0]; wire bit3 = bus[3];
bit0 and bit3 respectively?wire [7:0] data; wire [7:0] data_bus; assign data = data_bus[8];
control_signal where bit 11 is the most significant bit and bit 0 is the least significant bit. Which declaration is correct and why?wire [11:0] control_signal;wire [0:11] control_signal;wire control_signal[11:0];wire control_signal[0:11];wire [11:0] control_signal; because MSB must be higher index first correctly declares a 12-bit bus with MSB=11 and LSB=0. The options with wire control_signal[11:0]; and wire control_signal[0:11]; declare arrays, not buses. wire [0:11] control_signal; because LSB is first index reverses the range, which is legal but uncommon and can cause confusion.Pass the test and this pattern moves unknown