1

I have some basic code using data flow statements, but nor and nand functions are not working with this.

module basic_gates_bitwise_df(
input A,
input B,
output andd,orr,nota,nandd,norr,xorr,xnorr
);
assign andd=A&B;
assign orr=A|B;
assign nota=~A;
assign nandd=A~&B;
assign norr=A~|B ;
assign xorr=A^B;
assign xnorr=A~^B;
endmodule

I got errors like this:

ERROR:HDLCompiler:806 - "F:\basic.v" Line 37: Syntax error near "~&".
ERROR:HDLCompiler:806 - "F:\basic.v" Line 38: Syntax error near "~|".
ERROR:HDLCompiler:598 - "F:\basic.v" Line 21: 
Module<basic_gates_bitwise_df> ignored due to previous errors.

What can I try to resolve this?

1
  • what are ~& and others supposed to mean in your case? there are no such operators on two operands in verilog. They can only be used as unary reduction operators. What did you expect? Commented Nov 24, 2021 at 11:40

1 Answer 1

1

Sometimes you get a more helpful message with different simulators. For example, with Synopsys VCS on edaplayground:

Error-[SE] Syntax error
  Following verilog source has syntax error :
    Invalid use of unary operator '~&'
   token is ';'
  assign nandd=A~&B;
                    ^
1 error

To fix the errors, change:

assign nandd=A~&B;
assign norr=A~|B ;

to:

assign nandd=~(A&B);
assign norr=~(A|B);

Refer to IEEE Std 1800-2017, section 11.4.9 Reduction operators :

The unary reduction operators shall perform a bitwise operation on a single operand to produce a single-bit result.

For a NAND, you should AND the 2 inputs, then negate the AND expression.


There is no syntax error with ~^ because it is also a binary operator, as well as a unary operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.