0
    module fa(a,b,cin,cout,sum);
        input a;
        input b;
        wire bxor;
        input cin;
        output cout;
        output sum;

        assign  bxor = b ^ cin;
        assign  sum  = ((a^bxor)^(cin));
        assign  cout = ((a&bxor)|((a^bxor)&cin));
endmodule

module rca(a,b,cin,cout,sum);
        input cin;
        output cout;
        output [7:0] sum;
        input [7:0] a, b;
        wire c[6:0];     

        fa first(a[0],b[0],cin,c[0],sum[0]);
        fa second(a[1],b[1],c[0],c[1],sum[1]);
        fa third(a[2],b[2],c[1],c[2],sum[2]);
        fa fourth(a[3],b[3],c[2],c[3],sum[3]);
        fa fifth(a[4],b[4],c[3],c[4],sum[4]);
        fa sixth(a[5],b[5],c[4],c[5],sum[5]);
        fa seventh(a[6],b[6],c[5],c[6],sum[6]);
        fa eighth(a[7],b[7],c[6],cout,sum[7]);
endmodule

module alu_op(a,b,op,out);
        input [7:0] a, b;
        input [2:0] op;
        output [7:0] out;
        output reg out1;

        always @ (op or a or b)
                case (op)
                        3'b000 : out1 = fa(a, b, op[0], op[0], out);
                        3'b001 : out1 = fa(a,b,op[0], op[0], out);
                        //3'b010 : out = shift shifter (a[7:0],b[7:0],out[7:0]);
                        3'b011 : out1 = a ^ b;
                        3'b100 : out1 = a | b;
                        3'b101 : out1 = a & b;
                endcase
endmodule

我认为这是因为您不能在 case 语句中调用函数。我对此完全陌生,不知道该怎么做。我基本上是在做一个alu,前两个案例应该做add和sub。

当我编译时,我得到:

alutester.vl:66: error: No function fa in this context (alu.utt).
alutester.vl:67: error: No function rca in this context (alu.utt).

我不知道为什么。有人能帮助我吗?

4

2 回答 2

2

您没有一个名为的函数fa,而是创建了一个名为的模块fa(它们不是一回事)。而且你不能在程序块内实例化模块。

也不清楚你想用这些模块做什么。我不确定这意味着什么

out1 = fa(a, b, op[0], op[0], out);

首先,您将 op[0] 绑定到 cin 和 cout,这似乎是错误的,并且不清楚out1应该采用什么值。它应该得到加法器的总和输出吗?如果您想从 fa 的某个输出中取出 out1,则在 always 块之外对其进行实例化,并在您想要的情况下将 out1 设置为等于来自模块的线。

于 2013-11-26T16:09:57.080 回答
1

让我们看看...您已经构建了一个 8 位加法器,即rca模块。

稍后,您将拥有一个看似 ALU,它将ab作为输入操作数,并out1根据愿意执行的操作进行分配。

rca您可以在模块中实例化alu_op模块,以便获得aplus的总和b,...

module alu_op(a,b,op,out);
        input [7:0] a, b;
        input [2:0] op;
        output [7:0] out;
        output reg out1;

        wire [7:0] sum;
        rca my_adder(.a(a),.b(b),.cin(1'b0),.sum(sum))

        always @ (op or a or b)
                case (op)
                        3'b000 : out1 = sum;
                        //3'b010 : out = shift shifter (a[7:0],b[7:0],out[7:0]);
                        3'b011 : out1 = a ^ b;
                        3'b100 : out1 = a | b;
                        3'b101 : out1 = a & b;
                endcase
endmodule

或者(当然更好),让编译器通过使用运算符来弄清楚如何构建加法器+

module alu_op(a,b,op,out);
        input [7:0] a, b;
        input [2:0] op;
        output [7:0] out;
        output reg out1;

        always @ (op or a or b)
                case (op)
                        3'b000 : out1 = a + b;
                        //3'b010 : out = shift shifter (a[7:0],b[7:0],out[7:0]);
                        3'b011 : out1 = a ^ b;
                        3'b100 : out1 = a | b;
                        3'b101 : out1 = a & b;
                endcase
endmodule

顺便说一句:位移也是一个有效的 Verilog 操作数,而且,我很确定你想要减法(对于操作 001),减号-运算符也是可用的。加法、比特转换和减法也是可以合成的。

于 2013-11-26T16:42:46.737 回答