Reputation: 1433
In Verilog code
case ({Q[0], Q_1})
2'b0_1 :begin
A<=sum[7]; Q<=sum; Q_1<=Q;
end
2'b1_0 : begin
A<=difference[7]; Q<=difference; Q_1<=Q;
end
default: begin
A<=A[7]; Q<=A; Q_1<=Q;
end
endcase
is above code is same as below code
case ({Q[0], Q_1})
2'b0_1 : {A, Q, Q_1} <= {sum[7], sum, Q};
2'b1_0 : {A, Q, Q_1} <= {difference[7], difference, Q};
default: {A, Q, Q_1} <= {A[7], A, Q};
endcase
If yes then why i am getting different result?
Edit:-A, Q, sum and difference are all 8-bit values and Q_1 is a 1-bit value.
Upvotes: 0
Views: 245
Reputation: 389
Yes, they are same. For example try this small code and check, the output is same :
module test;
wire A,B,C;
reg p,q,r;
initial
begin
p=1; q=1; r=0;
end
assign {A,B,C} = {p,q,r};
initial #1 $display("%b %b %b",A,B,C);
endmodule
In general if you want to understand concatenation operator, you can refer here
Edit : I have assumed A and p , B and q, C and r of same length.
Upvotes: 0
Reputation: 5108
No, these are not the same. The concatenation operator ({ ... }
) allows you to create vectors from several different signals, allowing you to both use these vectors and assign to these vectors, resulting in the assignment of the component signals will the appropriate bits from the result. From your previous question (Please Explain these verilog code?), I see that A
, Q
, sum
and difference
are all 8-bit values and Q_1
is a 1-bit value. Lets examine the first assignment (noting that the other three work the same way):
{A, Q, Q_1} <= {sum[7], sum, Q};
If we look at the right-hand side, we can see that the result of the concatenation is a 17-bit vector, as sum[7]
is 1 bit (the MSb of sum
), sum
is 8 bits, and Q
is 8 bits (1 + 8 + 8 = 17). Lets say sum = 8'b10100101
and Q = 8'b00110110
, what would {sum[7], sum, Q}
look like? Well, its the concatenation of the values from sum
and Q
so it would be 17'b1_10100101_00110110
, the first bit coming from sum[7]
, the next 8 bits from sum
and the final 8 bits from Q
.
Now we have to assign this 17-bit value to the left hand side. On the left, we have {A, Q, Q_1}
, which is also 17 bits (A
is 8 bits, Q
is 8 bits and Q_1
is 1 bit). However, we have to assign the bits from our 17-bit value we got above to the proper signals that make up this new 17-bit vector, that means the 8 most significant bits go into A
, the next 8 bits go into Q
and the least significant bit go into Q_1
. So, if we take our value from above (17'b1_10100101_00110110
), and split it up this way (17'b11010010_10011011_0
), we see A = 8'b11010010
, Q = 8'b10011011
and Q_1 = 1'b0
. Thus, this is not the same as assigning A = sum[7]
, Q = sum
and Q_1 = Q
(this would result in A = 8'b00000001
, Q = 8'b10100101
, Q_1 = 1'b0
, with many bits of Q
being lost and A
having 7 extra bits).
However, this doesnt mean we cant split up the left-hand side concatenation, it would just look like this:
A <= {sum[7], sum[7:1]};
Q <= {sum[0], Q[7:1]};
Q_1 <= Q[0];
Upvotes: 2