|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
module mutiplier(count,a,b,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O);
output [31:0] count;
input [15:0] a,b;
wire [15:0] r0,r1,r2,HI;
wire [30:0] LO;
wire [15:0] HE1,HE2,HE3,HE4,HE5,HE6,HE7,HE8,HE9,HE10,
HE11,HE12,HE13,HE14,HE15,HE16,HE17,HE18,HE19,HE20,
HE21,HE22,HE23,HE24,HE25,HE26,HE27,HE28,HE29,HE30;
output [31:0] A,B,C,D,E,F,G,H,I,J,K,L,M,N,O;
assign r0=16'b0000_0000_0000_0000;
assign r1=a;
assign r2=b;
assign HI=r0-r2;
assign LO=31'b000_0000_0000_0000_0000_0000_0000_0000;
assign #1 A=a[0]?(({HI,r1}>>1)+({HI[15],LO}))
(({r0,r1})>>1)+({r0[0],LO}));
assign #3 HE1=(A[31:16]+r2);
assign #3 HE2=(A[31:16]-r2);
assign #4 B=(a[1:0]==2'b00)?((A>>1)+({A[31],LO}))
a[1:0]==2'b01)?(({A[31:16]+r2,A[15:0]}>>1)+({HE1[15],LO}))
a[1:0]==2'b10)?(({A[31:16]-r2,A[15:0]}>>1)+({HE2[15],LO}))
:((A>>1)+({A[31],LO}));
assign #5 HE3=(B[31:16]+r2);
assign #6 HE4=(B[31:16]-r2);
assign #7 C=(a[2:1]==2'b00)?(B>>1+({B[31],LO}))
:(a[2:1]==2'b01)?(({B[31:16]+r2,B[15:0]}>>1)+({HE3[15],LO}))
:(a[2:1]==2'b10)?(({B[31:16]-r2,B[15:0]}>>1)+({HE4[15],LO}))
:((B>>1)+({B[31],LO}));
assign #8 HE5=(C[31:16]+r2);
assign #9 HE6=(C[31:16]-r2);
assign #10 D=(a[3:2]==2'b00)?(C>>1+({C[31],LO}))
:(a[3:2]==2'b01)?(({C[31:16]+r2,C[15:0]}>>1)+({HE5[15],LO}))
:(a[3:2]==2'b10)?(({C[31:16]-r2,C[15:0]}>>1)+({HE6[15],LO}))
:((C>>1)+({C[31],LO}));
assign #11 HE7=(D[31:16]+r2);
assign #12 HE8=(D[31:16]-r2);
assign #13 E=(a[4:3]==2'b00)?(D>>1+({D[31],LO}))
:(a[4:3]==2'b01)?(({D[31:16]+r2,D[15:0]}>>1)+({HE7[15],LO}))
:(a[4:3]==2'b10)?(({D[31:16]-r2,D[15:0]}>>1)+({HE8[15],LO}))
:((D>>1)+({D[31],LO}));
assign #14 HE9=(E[31:16]+r2);
assign #15 HE10=(E[31:16]-r2);
assign #16 F=(a[5:4]==2'b00)?(E>>1+({E[31],LO}))
:(a[5:4]==2'b01)?(({E[31:16]+r2,E[15:0]}>>1)+({HE9[15],LO}))
:(a[5:4]==2'b10)?(({E[31:16]-r2,E[15:0]}>>1)+({HE10[15],LO}))
:((E>>1)+({E[31],LO}));
assign #17 HE11=(F[31:16]+r2);
assign #18 HE12=(F[31:16]-r2);
assign #19 G=(a[6:5]==2'b00)?(F>>1+({F[31],LO}))
:(a[6:5]==2'b01)?(({F[31:16]+r2,F[15:0]}>>1)+({HE11[15],LO}))
:(a[6:5]==2'b10)?(({F[31:16]-r2,F[15:0]}>>1)+({HE12[15],LO}))
:((F>>1)+({F[31],LO}));
assign #20 HE13=(G[31:16]+r2);
assign #21 HE14=(G[31:16]-r2);
assign #22 H=(a[7:6]==2'b00)?(G>>1+({G[31],LO}))
:(a[7:6]==2'b01)?(({G[31:16]+r2,G[15:0]}>>1)+({HE13[15],LO}))
:(a[7:6]==2'b10)?(({G[31:16]-r2,G[15:0]}>>1)+({HE14[15],LO}))
:((G>>1)+({G[31],LO}));
assign #23 HE15=(H[31:16]+r2);
assign #24 HE16=(H[31:16]-r2);
assign #25 I=(a[8:7]==2'b00)?(H>>1+({H[31],LO}))
:(a[8:7]==2'b01)?(({H[31:16]+r2,H[15:0]}>>1)+({HE15[15],LO}))
:(a[8:7]==2'b10)?(({H[31:16]-r2,H[15:0]}>>1)+({HE16[15],LO}))
:((H>>1)+({H[31],LO}));
assign #26 HE17=(I[31:16]+r2);
assign #27 HE18=(I[31:16]-r2);
assign #28 J=(a[9:8]==2'b00)?(I>>1+({I[31],LO}))
:(a[9:8]==2'b01)?(({I[31:16]+r2,I[15:0]}>>1)+({HE17[15],LO}))
:(a[9:8]==2'b10)?(({I[31:16]-r2,I[15:0]}>>1)+({HE18[15],LO}))
:((I>>1)+({I[31],LO}));
assign #29 HE19=(J[31:16]+r2);
assign #30 HE20=(J[31:16]-r2);
assign #31 K=(a[10:9]==2'b00)?(J>>1+({J[31],LO}))
:(a[10:9]==2'b01)?(({J[31:16]+r2,J[15:0]}>>1)+({HE19[15],LO}))
:(a[10:9]==2'b10)?(({J[31:16]-r2,J[15:0]}>>1)+({HE20[15],LO}))
:((J>>1)+({J[31],LO}));
assign #32 HE21=(K[31:16]+r2);
assign #33 HE22=(K[31:16]-r2);
assign #34 L=(a[11:10]==2'b00)?(K>>1+({K[31],LO}))
:(a[11:10]==2'b01)?(({K[31:16]+r2,K[15:0]}>>1)+({HE21[15],LO}))
:(a[11:10]==2'b10)?(({K[31:16]-r2,K[15:0]}>>1)+({HE22[15],LO}))
:((K>>1)+({K[31],LO}));
assign #35 HE23=(L[31:16]+r2);
assign #36 HE24=(L[31:16]-r2);
assign #37 M=(a[12:11]==2'b00)?(L>>1+({L[31],LO}))
:(a[12:11]==2'b01)?(({L[31:16]+r2,L[15:0]}>>1)+({HE23[15],LO}))
:(a[12:11]==2'b10)?(({L[31:16]-r2,L[15:0]}>>1)+({HE24[15],LO}))
:((L>>1)+({L[31],LO}));
assign #38 HE25=(M[31:16]+r2);
assign #39 HE26=(M[31:16]-r2);
assign #40 N=(a[13:12]==2'b00)?(M>>1+({M[31],LO}))
:(a[13:12]==2'b01)?(({M[31:16]+r2,M[15:0]}>>1)+({HE25[15],LO}))
:(a[13:12]==2'b10)?(({M[31:16]-r2,M[15:0]}>>1)+({HE26[15],LO}))
:((M>>1)+({M[31],LO}));
assign #41 HE27=(N[31:16]+r2);
assign #42 HE28=(N[31:16]-r2);
assign #43 O=(a[14:13]==2'b00)?(N>>1+({N[31],LO}))
:(a[14:13]==2'b01)?(({N[31:16]+r2,N[15:0]}>>1)+({HE27[15],LO}))
:(a[14:13]==2'b10)?(({N[31:16]-r2,N[15:0]}>>1)+({HE28[15],LO}))
:((N>>1)+({N[31],LO}));
assign #44 HE29=(O[31:16]+r2);
assign #45 HE30=(O[31:16]-r2);
assign #46 count=(a[15:14]==2'b00)?(O>>1+({O[31],LO}))
:(a[15:14]==2'b01)?(({O[31:16]+r2,O[15:0]}>>1)+({HE29[15],LO}))
:(a[15:14]==2'b10)?(({O[31:16]-r2,O[15:0]}>>1)+({HE30[15],LO}))
:((O>>1)+({O[31],LO}));
endmodule
module stimulus_liuheng;
wire [31:0] count;
reg [15:0] a,b;
wire [31:0] A,B,C,D,E,F,G,H,I,J,K,L,M,N,O;
mutiplier test(count,a,b,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O);
initial
begin
$monitor($time,", a=%d,b=%d,count=%d",a,b,count);
#0 a=9;
b=6;
forever #400 b=b+3;
end
initial
# 10000 $finish;
endmodule |
|