2013-11-26 30 views
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語句中調用函數。我對此完全陌生,不知道該怎麼做。我基本上做了一個鋁,前兩個案件應該做添加和分。verilog沒有看到我的功能

我編譯時得到:

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

我不知道爲什麼。有人能幫助我嗎?

+0

我試圖使用我在那裏的波紋進位加法器,但我無法弄清楚如何使用全加器。如果rca會更好,請讓我知道 – user2197126

回答

2

你沒有功能fa,您創建了一個模塊稱爲fa(它們不是一回事)。而且你不能在程序塊內實例化模塊。

你也不清楚你想用這些模塊做什麼。我不知道這是什麼意思

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

首先,你綁運[0]雙方CIN和COUT,這似乎是錯誤的,目前還不清楚應該採取什麼樣的價值out1 。它應該得到加法器的總和輸出嗎?如果你想從fa的某些輸出中取出1,然後在always塊外面實例化它,並且在需要的情況下將out1設置爲等於來自模塊的連線。

+0

op [0]選擇您想要執行的操作的第一位。 0或1.如果它是0,則它會加減1(假設它是1)。out1應該是alu的輸出。 – user2197126

+0

在這種情況下,您需要將op [0]與'cout'斷開連接,因爲這會給您信號上的線路爭用並強制爲'x'。在程序塊之外實例化ALU,將ALU的輸出分配給導線,然後在要從ALU輸出中採樣的情況下將導線連接到OUT1 – Tim

1

讓我們來看看......您已經構建了一個8位加法器rca模塊。

後來,你有什麼似乎是一個ALU這需要ab作爲輸入操作數,並依據是願意要執行的操作分配out1

要麼你實例化你的alu_op模塊中的rca模塊,以便有可用的ab總和,...

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 

BTW:位移位也是一個有效的Verilog操作,而且,我敢肯定你想減法(操作001),減號-運營商可用。另外,位刪除和減法也是可以合成的。