Exp 2
Exp 2
TTL:
RTL:
TTL:
CODE:
module exp2( A,B,Cin,sum,Cout);
input [3:0]A,B; input Cin; output [3:0]sum; output Cout;
wire x0,x1,x2;
fulladder abc0 (A[0],B[0],Cin,sum[0],x0);
fulladder abc1 (A[1],B[1],x0,sum[1],x1);
fulladder abc2 (A[2],B[2],x1,sum[2],x2);
fulladder (A[3],B[3],x2,sum[3],Cout);
endmodule
module fulladder(input a,b,c,output s,co);
assign s = a^b^c;
assign co = (c&(a^b)) | (a&b);
endmodule
RTL:
TTL:
4) Modify the code that can perform Addition and Subtraction operation using a ‘Mode
Control Switch’:
CODE:
module exp2(input a,b,cin,mode,output reg sum,cout,sub,bout);
always @ (*) begin
sum=0;
sub=0;
cout=0;
bout=0;
case (mode) 0:
begin
sum = a ^b ^cin; cout = (a&b) | (cin&(a^b));
end
1: begin
sub = a ^b ^cin; bout = ((~a)&b) | (cin&(~(a^b)));
end
endcase
end
endmodule
RTL:
TTL:
CODE:
module exp2( A,B,Cin,m,sum,Cout);
input [3:0]A,B; input Cin,m; output [3:0]sum; output Cout;
wire x0,x1,x2;
fulladder abc0 (A[0],B[0]^m,Cin,sum[0],x0);
fulladder abc1 (A[1],B[1]^m,x0,sum[1],x1);
fulladder abc2 (A[2],B[2]^m,x1,sum[2],x2);
fulladder abc3(A[3],B[3]^m,x2,sum[3],Cout);
endmodule
module fulladder (input a,b,c,output s,co);
assign s = a^b^c;
assign co = (c&(a^b)) | (a&b);
endmodule
RTL:
TTL:
RTL:
TTL:
7) Multiplexer using Case statement :-
module exp2(input [3:0]in , input [1:0]sel , output reg out);
always @(*) begin
case(sel)
2'b00 : out = in[0];
2'b01 : out = in[1];
2'b10 : out = in[2];
2'b11 : out = in[3];
default : out = 1'b0;
endcase
end
endmodule
RTL:
TTL:
RTL:
TTL:
RTL:
TTL:
CODE:
module exp2 (input [1:0]in , output reg [3:0]out );
always @(*) begin
case (in)
endmodule
TTL:
RTL:
TTL: