title: Why cant my verilog testbench display intermediate variables?
body: <p>I want to see what value is stored in a1 and b1 but I get only "xxxxxx" as output. Why?</p>
  
  <p>My code is designed to take values of a and b which are 4 bit signed numbers. I am using intermediate variables a1 and b1 to make 2's complement of those numbers if the MSB of a or b is 1 otherwise use the same a and b for my main code. But I am not able to get the intermediate values. </p>
  
  <p>Relevant code and testbench;</p>
  
  <pre><code>module xx(a,b,z);
      input   signed [3:0] a,b;
      output  signed [7:0] z;
      integer i;
      wire w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12;    
      reg [3:0] pp0,pp1,pp2,pp3;
      reg [3:0] a1,b1;
  
     always @ (a or b)  begin  
        if ( a[3] == 1 &amp;&amp; b[3] == 1) begin
            a1 &lt;= ~a + 1;
            b1 &lt;= ~b + 1;
        end else if ( a[3] == 1 &amp;&amp; b[3] == 0) begin
            a1 &lt;= ~a + 1;
            b1 &lt;=b;
        end else if ( a[3] == 0 &amp;&amp; b[3] == 1) begin
            a1 &lt;= a;
            b1 &lt;= ~b + 1;
        end else begin
            a1 &lt;= a;
            b1 &lt;= b;
        end
     end
  .....
  endmodule
  </code></pre>
  
  <p>Testbench</p>
  
  <pre><code>module xxt();
      reg  signed [3:0]a,b;
      wire  signed [7:0]z;
      reg [3:0] a1,b1; 
  
      xx w1(a,b,z);
  
      integer i;
      integer j;
  
      initial
      begin
          for ( i = 0; i&lt;16; i = i + 1)
          begin
              for ( j = 16; j&gt;0; j = j - 1)
              begin
                  #10 b=j; a=i;
                  //$display("a*b=z %d %d %d", a, b, z);
                  //$display("a*b=z %b %b %b", a, b, z);
                  $display("%t\ta\tb\ta1\tb1\tz\n\t\t%b\t%b\t%b\t%b\t%b", $time, a, b, a1, b1, z);
                  $display("%t\t%d\t%d\t%d\t%d\t%d", $time, a, b, a1, b1, z);
              end
          end
      end
  
  
  endmodule
  </code></pre>
  
  <p>My transcript displays only this</p>
  
  <pre><code> 10 a   b   a1  b1  z
  #       0000    0000    xxxx    xxxx    xxxxxxxx
  #                   10    0   0  x   x     x
  #                   20  a   b   a1  b1  z
  #       0000    1111    xxxx    xxxx    xxxxxxxx
  #                   20    0  -1  x   x     x
  #                   30  a   b   a1  b1  z
  #       0000    1110    xxxx    xxxx    00000000
  #                   30    0  -2  x   x     0
  #                   40  a   b   a1  b1  z
  #       0000    1101    xxxx    xxxx    00000000
  #                   40    0  -3  x   x     0
  #                   50  a   b   a1  b1  z
  #       0000    1100    xxxx    xxxx    00000000
  #                   50    0  -4  x   x     0
  #                   60  a   b   a1  b1  z
  #       0000    1011    xxxx    xxxx    00000000
  #                   60    0  -5  x   x     0
  #                   70  a   b   a1  b1  z
  #       0000    1010    xxxx    xxxx    00000000
  #                   70    0  -6  x   x     0
  #                   80  a   b   a1  b1  z
  #       0000    1001    xxxx    xxxx    00000000
  #                   80    0  -7  x   x     0
  #                   90  a   b   a1  b1  z
  #       0000    1000    xxxx    xxxx    00000000
  #                   90    0  -8  x   x     0
  #                  100  a   b   a1  b1  z
  #       0000    0111    xxxx    xxxx    00000000
  #                  100    0   7  x   x     0
  #                  110  a   b   a1  b1  z
  #       0000    0110    xxxx    xxxx    00000000
  #                  110    0   6  x   x     0
  #                  120  a   b   a1  b1  z
  #       0000    0101    xxxx    xxxx    00000000
  #                  120    0   5  x   x     0
  #                  130  a   b   a1  b1  z
  #       0000    0100    xxxx    xxxx    00000000
  #                  130    0   4  x   x     0
  #                  140  a   b   a1  b1  z
  #       0000    0011    xxxx    xxxx    00000000
  #                  140    0   3  x   x     0
  #                  150  a   b   a1  b1  z
  #       0000    0010    xxxx    xxxx    00000000
  #                  150    0   2  x   x     0
  #                  160  a   b   a1  b1  z
  #       0000    0001    xxxx    xxxx    00000000
  #                  160    0   1  x   x     0
  ....
  
  and so on
  </code></pre>