4bit 減法器 適用於DE2-70實驗板
module Full_sub_4bit (SW, LEDR, LEDG);
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red LEDS
output [7:0] LEDG; // green LEDs
//set original program input , output
wire [3:0]X, Y;
wire Bin;
wire [3:0]Dif;
wire Bout;
wire Bout1,Bout2,Bout3;
//mapping to hardware
assign LEDR = SW;
//assign SW to input
assign Y=SW[3:0];
assign X=SW[7:4];
assign Bin=SW[17];
// X - Y -Bin = Bout , Dif
//Assign difference and borrow
//full_sub_1bit(X, Y, Bin, Dif, Bout);
full_sub_1bit UUT1 (.X(X[0]),.Y(Y[0]),.Bin(Bin),.Dif(Dif[0]),.Bout(Bout1));
full_sub_1bit UUT2 (.X(X[1]),.Y(Y[1]),.Bin(Bout1),.Dif(Dif[1]),.Bout(Bout2));
full_sub_1bit UUT3 (.X(X[2]),.Y(Y[2]),.Bin(Bout2),.Dif(Dif[2]),.Bout(Bout3));
full_sub_1bit UUT4 (.X(X[3]),.Y(Y[3]),.Bin(Bout3),.Dif(Dif[3]),.Bout(Bout));
assign LEDG[3:0]=Dif;
assign LEDG[4]=Bout;
endmodule
//=============================================
//*original program
//-------------------------------------
//Filename : fadd1_df.v
//-------------------------------------
module full_sub_1bit(X, Y, Bin, Dif, Bout);
input X, Y, Bin;
output Dif, Bout;
//Assign difference and borrow
assign Dif = (((~X)&(~Y)&Bin)|((~X)&(Y)&(~Bin))|(X&(~Y)&(~Bin))|(X & Y & Bin));
assign Bout = (((~X)&Y)|((~X)&Bin)|(Y & Bin));
endmodule
沒有留言:
張貼留言