module tambahkali(input[4:0]X,Y,input select,output[9:0]C,K,output reg[6:0]seven_seg0,seven_seg1,seven_seg2,seven_seg3,output reg[3:0]bcd0,bcd1,bcd2);
always @ (*)
begin
case (select)
1'b0: adder2(X,Y,C);
1'b1: multiplier(X,Y,C);
endcase
bcd(C,K,seven_seg3,bcd0,bcd1,bcd2);
sevensegment(bcd0,seven_seg0);
sevensegment1(bcd1,seven_seg1);
sevensegment2(bcd2,seven_seg2);
end
task adder2(input [4:0] X, Y, output reg [9:0] C);
begin
if ((X[4]==0)&(Y[4]==0))
C=({5'b00000,X}+({5'b00000,Y}));
else if ((X[4]==0)&(Y[4]==1))
C=({5'b00000,X}+({5'b11111,Y}));
//else if ((A[4]==0)&(B[4]==1))
//C=({5'b00000,A}+({5'b11111,B}));
else if ((X[4]==1)&(Y[4]==0))
C=({5'b11111,X}+({5'b00000,Y}));
//else if ((A[4]==1)&(B[4]==0))
//C=~({5'b11111,A}+({5'b00000,B}));
else if ((X[4]==1)&(Y[4]==1))
C=({5'b11111,X}+({5'b11111,Y}));
end
endtask
task multiplier(input [4:0] X, Y, output reg [9:0] C);
begin
if ((X[4]==0)&(Y[4]==0))
C=X*Y;
else if ((X[4]==0)&(Y[4]==1))
C=~({5'b00000,X}*(~{5'b11111,Y}+1'b1))+1'b1;
else if ((X[4]==1)&(Y[4]==0))
C=~((~{5'b11111,X}+10'b0000000001)*{5'b00000,Y})+10'b0000000001;
else if ((X[4]==1)&(Y[4]==1))
C=(~{5'b11111,X}+1'b1)*(~{5'b11111,Y}+1'b1);
end
endtask
task bcd(input[9:0]C,K,output[6:0]seven_seg3,output reg[3:0]bcd0,bcd1,bcd2);
begin
if (C[9]==1)
K=(~{10'b1111111111,C}+1'b1);
else
K=C;
end
begin
if (C[9]==1)
seven_seg3 = 7'b1111110;
else
seven_seg3 = 7'b1111111;
end
bcd0 =K%10;
bcd1=((K-bcd0)/10)%10;
bcd2=(((K-bcd1)/100)%10);
endtask
task sevensegment(input[3:0]bcd0,output reg [6:0] seven_seg0);
case (bcd0)
4'b0000:seven_seg0 = 7'b0000001;
4'b0001:seven_seg0 = 7'b1001111;
4'b0010:seven_seg0 = 7'b0010010;
4'b0011:seven_seg0 = 7'b0000110;
4'b0100:seven_seg0 = 7'b1001100;
4'b0101:seven_seg0 = 7'b0100100;
4'b0110:seven_seg0 = 7'b0100000;
4'b0111:seven_seg0 = 7'b0001111;
4'b1000:seven_seg0 = 7'b0000000;
4'b1001:seven_seg0 = 7'b0000100;
4'b1010:seven_seg0 = 7'b0001000;
4'b1011:seven_seg0 = 7'b1100000;
4'b1100:seven_seg0 = 7'b0110001;
4'b1101:seven_seg0 = 7'b1000010;
4'b1110:seven_seg0 = 7'b0110001;
4'b1111:seven_seg0 = 7'b0111000;
endcase
endtask
task sevensegment1(input[3:0]bcd1,output reg [6:0] seven_seg1);
case (bcd1)
4'b0000:seven_seg1 = 7'b0000001;
4'b0001:seven_seg1 = 7'b1001111;
4'b0010:seven_seg1 = 7'b0010010;
4'b0011:seven_seg1 = 7'b0000110;
4'b0100:seven_seg1 = 7'b1001100;
4'b0101:seven_seg1 = 7'b0100100;
4'b0110:seven_seg1 = 7'b0100000;
4'b0111:seven_seg1 = 7'b0001111;
4'b1000:seven_seg1 = 7'b0000000;
4'b1001:seven_seg1 = 7'b0000100;
4'b1010:seven_seg1 = 7'b0001000;
4'b1011:seven_seg1 = 7'b1100000;
4'b1100:seven_seg1 = 7'b0110001;
4'b1101:seven_seg1 = 7'b1000010;
4'b1110:seven_seg1 = 7'b0110001;
4'b1111:seven_seg1 = 7'b0111000;
endcase
endtask
task sevensegment2(input[3:0]bcd2,output reg [6:0] seven_seg2);
case (bcd2)
4'b0000:seven_seg2 = 7'b0000001;
4'b0001:seven_seg2 = 7'b1001111;
4'b0010:seven_seg2 = 7'b0010010;
4'b0011:seven_seg2 = 7'b0000110;
4'b0100:seven_seg2 = 7'b1001100;
4'b0101:seven_seg2 = 7'b0100100;
4'b0110:seven_seg2 = 7'b0100000;
4'b0111:seven_seg2 = 7'b0001111;
4'b1000:seven_seg2 = 7'b0000000;
4'b1001:seven_seg2 = 7'b0000100;
4'b1010:seven_seg2 = 7'b0001000;
4'b1011:seven_seg2 = 7'b1100000;
4'b1100:seven_seg2 = 7'b0110001;
4'b1101:seven_seg2 = 7'b1000010;
4'b1110:seven_seg2 = 7'b0110001;
4'b1111:seven_seg2 = 7'b0111000;
endcase
endtask
endmodule
wuuuuoooooo~stress jer wat benda... alhmdllh success... :))
No comments:
Post a Comment