๐ชข Explicit Part-Selects
TL:DR
A part-select extracts or assigns a contiguous slice of bits from a vector.
Syntax: vector[high:low] โ must match the direction of the declaration.
TL:DR
A part-select extracts or assigns a contiguous slice of bits from a vector.
Syntax:
Syntax:
vector[high:low] โ must match the direction of the declaration.โ Why Use Explicit Part-Selects?
| Benefit | Description |
|---|---|
| ๐งฉ Symbolic trace clarity | Makes bit ranges visible and auditable |
| ๐ Onboarding-friendly | Easier for new readers to follow intent |
| ๐ Refactor-safe | Protects against silent errors if widths change |
| ๐ง Directional safety | Enforces correct slicing semantics |
๐งฉ Examples of Explicit Part-Selects
โ Extracting a slice
wire [15:0] word;
wire [3:0] nibble;
assign nibble = word[11:8]; // โ
Extract middle nibble
โ Assigning to a slice
reg [15:0] word;
reg [3:0] nibble;
assign word[11:8] = nibble; // โ
Overwrite middle nibble
โ Safe inversion with part-select
input [2:0] a, b;
output [5:0] out_not;
assign out_not[2:0] = ~a[2:0]; // โ
Invert a explicitly
assign out_not[5:3] = ~b[2:0]; // โ
Invert b explicitly
โ ๏ธ Common Pitfall: Implicit Width Assumptions
assign out_not[2:0] = ~a; // โ ๏ธ Relies on knowing a is [2:0]
- Works if
ais[2:0], but less explicit - Risky if
achanges width later
๐ง Directional Reminder
Declaration
wire [0:7] data; // Ascending index
Legal part-select
data[0:3]; // โ
Matches declaration direction
Illegal part-select
data[3:0]; // โ Direction mismatch
Last updated on