p.chives
p.chives

Reputation: 125

Can't output results of calculations

I'm trying to output the result of some multiplications and adders. As far as I can tell I've coded everything correctly (system compiles, seems consistent with examples I've seen) but it doesn't output the values of any assigned/calculated variables. Clearly there is something wrong or missing.

I've pasted my code below:


module multiplier_4x4(

logic [1:0] a,b,
output logic [3:0] c,
logic [3:0] p,
input logic cin = 0,
output logic cout = 0
);

assign a = 2'b11;
assign b = 2'b11;

assign c[0] = a[0] & b[0];
fulladder FA1(a[1]&b[0], a[0]&b[1], 1'b0, c[1], p[0]);
fulladder FA2(b[1]&a[1], 1'b0, cin, c[2], p[1]);
assign c[3] = p[1];

initial begin

    $display("Output %d", c[1]);
    $display("Output %d", c);
    $display("Output %d", a);
    $display("Output %d", a[0]);
    $display("Output %d", 1'b1);
end

endmodule


module fulladder(input logic a, b, cin,
                 output logic s, cout);
  wire p, g;
  assign p = a ^ b;
  assign g = a & b;
  assign s = p ^ cin;
  assign cout = g | (p & cin);
endmodule

The display lines output the following (in order of appearance):

x
x
x
x
1

I would have expected the x values to represent actual numbers/variables. Where did I go wrong?

Upvotes: 0

Views: 54

Answers (1)

Mikef
Mikef

Reputation: 2510

The simulation in the post does nothing because it was running for 0 time.
Make this change so that it runs for at least a single time step before displaying the results:

initial begin
    #1;
    $display("Output %d", c[1]);
    $display("Output %d", c);
    $display("Output %d", a);
    $display("Output %d", a[0]);
    $display("Output %d", 1'b1);
end

Produces:

# Output 0
# Output  5
# Output 3
# Output 1
# Output 1

Upvotes: 1

Related Questions