Sign in

Learn

0/8
0/6
0/6
0/6

Practice

Try the challenge first: Bus Width Adapter

Know this topic? Give it a go. The lesson is here if you need it.

Concatenation and Replication

Concatenation assembles a word from smaller fields. The leftmost piece occupies the most significant bits, and the field widths add together. It extends the slice-and-repack work into one expression.

Repair a swapped word

A device expects two four-bit fields: hi_i first, then lo_i. With hi_i = 0011 and lo_i = 0101, its expected byte is hexadecimal 35. A proposed implementation returns 53.

Before reading the syntax, draw where each input bit belongs. Which field was placed in bits 7 through 4?

byte_o <= hi_i & lo_i;

The incorrect result reverses the two fields. A test with both fields equal would hide that mistake. Use distinct patterns when testing assembly.

Four bits plus four bits produce eight bits. Concatenation itself is fixed wiring, not an adder. That does not mean the physical connections have zero routing delay.

The & operator joins vectors, single bits, and literals. The resulting width must match the assigned vector.

Put padding on the correct side

A four-bit unsigned value can be widened without changing its value by adding zeros on the left:

wide_o <= "0000" & lo_i;

Putting one zero on the right instead shifts each input bit to the next higher weight:

dbl_o <= "000" & lo_i & '0';

For lo_i = 0101, the output becomes 00001010. The input represents 5; shifting its bits left by one makes their weights twice as large, producing 10. The eight-bit destination also holds the maximum input 15 doubled to 30.

A fixed shift is wiring. A signal-selected shift amount requires selection hardware.

Repeat a sign bit, not a guessed constant

Sign extension repeats the original sign bit when widening a signed representation. For the four-bit offset off_i, the sign bit is bit 3.

ext_o <= off_i(3) & off_i(3) & off_i(3) & off_i(3) & off_i;

Here the four copies are written explicitly. Numeric resize and aggregates provide other useful forms once their types and syntax are introduced.

Someone replaces the repeated sign bit with four constant ones. That implementation passes a test using 1101, which represents -3. Choose a positive offset that exposes the mistake before looking at the example.

For instance, +3 should extend from 0011 to 00000011. Constant-one padding gives 11110011, interpreted as -13. Correct handling of one negative test does not prove correct sign extension.

Check the three jobs separately

Open Wider, Three Ways in the example panel on the right. Its word_builder source performs assembly, doubling, and sign extension on separate outputs.

At the first waveform step, find byte_o = 35, dbl_o = 0A, and ext_o = 03 in hexadecimal. Those mean 53, 10, and +3 respectively. The next step changes off_i to 1101; ext_o becomes FD, the eight-bit representation of -3.

A check for field order does not replace a check for signed padding. The bus-width adapter exercise asks you to apply these operations to a different interface.

Key Takeaways

  • Concatenation orders fields from most significant to least significant; their widths add.
  • Zero padding on the left preserves an unsigned value; a zero on the right performs a fixed left shift.
  • Sign extension copies the sign bit, so verify both positive and negative inputs.
Loading editor...
No waveform is available for this example. You can continue with the lesson and example code.