Discussion:
[問題]Verilog
(时间太久无法回复)
我要喝牛奶
2003-12-25 05:28:46 UTC
Permalink
題目是要做一個3-bit的full adder (有要求先做1-bit的full adder)

CI是carry in ;CO 是carry out

Input (A,B,CI) 要從0跑到127 (是BINARY表示法0~127需三位數 AB(CI) )

A:3-bit B:3-bit SUM:3-bit CI, CO :1-bit

我的問題好像是出在SUM被設定為1-bit 無法表示題目要的

可以幫我找找哪裡錯了媽 謝謝....


`timescale 100ns/100ns
module Adder1(CO,SUM,A,B,CI);
output CO,SUM;
input A,B,CI;

and a1(a1_o,A,B);
and a2(a2_o,A,CI);
and a3(a3_o,B,CI);
or o1(CO,a1_o,a2_o,a3_o);
xor xo1(SUM,A,B,CI);

specify
(A, B, CI *> CO)=1;
(A, B, CI *> SUM)=1;
endspecify
endmodule

module Adder3(CO,SUM,A,B,CI);
output CO;
output [2:0]SUM;
input [2:0]A, B;
input CI;
Adder1 add1(CO_1,SUM[0],A[0],B[0],CI);
Adder1 add2(CO_2,SUM[1],A[1],B[1],CO_1);
Adder1 add3(CO,SUM[2],A[2],B[2],CO_2);
endmodule

module test;
reg[2:0]A,B;
reg CI;

Adder3 add(CO,SUM,A,B,CI);
initial begin
A=0;
B=0;
CI=0;
SUM=3'b000;
end

always #640 A[2]=~A[2];
always #320 A[1]=~A[1];
always #160 A[0]=~A[0];

always #80 B[2]=~B[2];
always #40 B[1]=~B[1];
always #20 B[0]=~B[0];

always #10 CI=~CI;


initial begin
#1300 $finish;
end

endmodule

--
□ 本文章由 jeanie 從 JaiHui.f2.ntu.edu.tw 發表
□ 本文章由 jeanie 在 2003/12/25 Thu 13:28:46 修改
John Doe
2003-12-25 18:12:55 UTC
Permalink
Post by 我要喝牛奶
我的問題好像是出在SUM被設定為1-bit 無法表示題目要的
module test;
reg[2:0]A,B;
reg CI;
Adder3 add(CO,SUM,A,B,CI);
initial begin
A=0;
B=0;
CI=0;
SUM=3'b000;
end
SUM沒有宣告,內定是 1-bit
在reg CI; 處加個 reg [2:0] SUM;

继续阅读narkive:
Loading...