\$\begingroup\$
\$\endgroup\$
20
this is my code:
module zero(out,A,B);
output signed[5:0] out;
input signed[5:0] A,B;
assign out = A[5:0]<<<2 + B[5:0]>>>1;
endmodule
but the output is always zero.
is there anything wrong?
(I don't want to use @always)
-
\$\begingroup\$ is this a school assignment? \$\endgroup\$jsotola– jsotola2019年01月19日 21:23:06 +00:00Commented Jan 19, 2019 at 21:23
-
\$\begingroup\$ Can you share your testbench? \$\endgroup\$The Photon– The Photon2019年01月19日 21:23:49 +00:00Commented Jan 19, 2019 at 21:23
-
\$\begingroup\$ How do you know that the output is always zero? \$\endgroup\$Elliot Alderson– Elliot Alderson2019年01月19日 21:24:06 +00:00Commented Jan 19, 2019 at 21:24
-
\$\begingroup\$ I am new to hardware description languages and because of this i can't handle this @jsotola \$\endgroup\$mohamadreza– mohamadreza2019年01月19日 21:24:19 +00:00Commented Jan 19, 2019 at 21:24
-
\$\begingroup\$ Please answer the three questions that were asked in the first three comments to your question. Even if you are new to HDL you should be able to answer these questions. \$\endgroup\$Elliot Alderson– Elliot Alderson2019年01月19日 21:25:12 +00:00Commented Jan 19, 2019 at 21:25
1 Answer 1
\$\begingroup\$
\$\endgroup\$
From our discussion in comments, it seems the problem is operator precedence. According to this, +
has higher precedence than <<<
, so your expression will calculate (A <<< (2 + B)) >>> 1
rather than what you might expect.
This can be solved by adding parentheses to ensure the expected order of operations.
answered Jan 19, 2019 at 22:05
lang-vhdl