keysymbols: {, }
The concatenation operator appends sized nets, registers, bit select, part select and constants.
module concatTest; reg a; reg [1:0] b; reg [5:0] c; initial begin a = 1'b1; b = 2'b00; c = 6'b101001; $displayb({a, b}); // produces a 3-bit number 3'b100 $displayb({c[5:3], a}); // produces 4-bit number 4'b1011 end endmodule // concatTest
Replication can be used along side concatenation to repeat a number as many times as specified, see example below.
module replicTest; reg a; reg [1:0] b; reg [5:0] c; initial begin a = 1'b1; b = 2'b00; $displayb({4{a}}); // evaluates as 1111 c = {4{a}}; $displayb(c); // evaluates as 001111 end endmodule // replicTest
According to the IEEE standard, replication and concatenation can be combined as in: c = {4{a}, b} however, the current software at Edinburgh University does not allow this.
EXERCISE
What does
d
evaluate to in the following ?
module replicTest2; reg a; reg [1:0] b; reg [3:0] c; reg [9:0] d; initial begin a = 1'b1; b = 2'b01; c = {4{a}}; d = {b, c, b}; $displayb(d); end endmodule // replicTest2