-1
  1. What is the difference between using ~ tilde and ! exclamation for not or inverting a signal.

    always @(posedge clock) 
    begin
      z=(!x&!y&Q1); 
      Q1=(~x&~y|z);
    end
    
  2. What difference will it make if the non blocking = was taken off and replaced as in code below.

    always @(posedge clock) 
    begin
      z<=(!x&!y&Q1); 
      Q1<=(~x&~y|z);
    end
    
Plouff
  • 3,290
  • 2
  • 27
  • 45
newb7777
  • 517
  • 5
  • 22

1 Answers1

2
  • ! is logical
  • ~ is bit-wise

In other words:

  • !a means "a is not 0"
  • ~a means "invert the bits of a"

For you second question:

The first code snippet is wrong. You can't use non blocking assignments for sequential logic. If you need combinatorial logic:

always @(x, y, Q1, z) # or always @(*)
begin
  z=(!x&!y&Q1);  // here, you have to use blocking assignment as it is combo logic
  Q1=(~x&~y|z);
end
Prakash Darji
  • 990
  • 6
  • 13
Plouff
  • 3,290
  • 2
  • 27
  • 45
  • Just to clarify and better understanding, the reason why the sensitive list contains all the variables is because the assignments on the LHS (eg z, Q1) need to be driven by the inputs on RHS which are x, y, Q1, z. If the sensitive list was made of clock only, then the only time the assignments z, Q1 will change is during positive edge of clock and not due to an input change. – newb7777 Apr 06 '16 at 08:07
  • @newb7777: You shouldn't try to understand that with sentences like *"X value will change when ..."*. You should try to have in mind a "physical" representation of the gates that would be produced. The sensitivity list is something that your compiler and simulator need to properly emulate the behavior of the gates you are about to create. I haven't read it, but this might help: https://www.edgefx.in/digital-logic-circuits/ . – Plouff Apr 06 '16 at 08:14
  • @newb7777: In other words, combinatorial logic and sequential logic have completely different behavior. Understanding those differences is a mandatory requirement to design hardware using HDL languages. – Plouff Apr 06 '16 at 08:16