-2
\$\begingroup\$

what is the difference between the following 3 sign extensions

wire signed [7:0] a;

wire signed [10:0] a_sxtnd1;
wire signed [10:0] a_sxtnd2;
wire signed [10:0] a_sxtnd3;

assign a_sxtnd1 = $signed(a);
assign a_sxtnd2 = $signed(  { {3{a[7]}} ,a}  );
assign a_sxtnd3 = $signed(  { 3'd0 ,a}  );

What are the differences and anyone of them will fail?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

There is no need for $signed in all three assignments.

In the first assignment to a_sxtnd1, both the LHS and RHS are signed, to a will be implicitly sign extended from 8 bits to 11 bits

In the second assignment to a_sxtnd2, you are explicitly sign extending a to an 11-bit result.

In the third assignment to a_sxtnd3, you are explicitly zero extending a to an 11-bit result.

So the third assignment is not like the other two, if that is what you mean by "fail"

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.