Question

I have to make a alu within a ralu that was 8 functions , but when I try to simulate the behavioral model for "ralu" all I get are X's (output) and Z's (input). What am I doing wrong? (When I simulate only the alu it works just fine)

module alu(
      input [3:0] op1,
      input [3:0] op2,
      input [2:0] func,
      output reg[3:0] out
    );
always@(*)
  case(func)
    3'b000: out=op1&op2; // functia AND
    3'b001: out=op1|op2; // OR
    3'b010: out=~(op1&op2);// NAND
    3'b011: out=~(op1|op2); //NOR
    3'b100: out=op1^op2; // XOR
    3'b101: out=op1~^op2; //XNOR
    3'b110: out=op1+op2;
    3'b111: out=op1-op2;
  endcase
endmodule

module ralu(
      input [3:0] in,
      input [2:0] func,
      input clk,
      input load,
      output [3:0] out
    );
reg [3:0] op1;
reg [3:0] op2;
always@(posedge clk)
  if(load) op2<=in;
  else op1<=in;
endmodule  
Was it helpful?

Solution

You're missing declaration of alu in ralu, i.e.:

alu myALU(
    .op1(op1),
    .op2(op2),
    .func(func),
    .out(out)
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top