HDL Manual (18ecl58)
HDL Manual (18ecl58)
module Decoder2_4(D0,D1,D2,D3,A0,A1);
output D0,D1,D2,D3;
input A0,A1;
wire w1,w2,w3,w4,w5,w6;
nand x1(w1,A0,AO);
nand x2(w2,A1,A1);
nand x3(w3,w1,w2);
nand x4(w4,A0,w2);
nand x5(w5,w1,A1);
nand x6(w6,A0,A1);
nand x7(D0,w3,w3);
nand x8(D1,w4,w4);
nand x9(D2,w5,w5);
nand x10(D3,w6,w6);
endmodule
module stimulus();
reg A0,A1;
wire D0,D1,D2,D3;
initial
begin
A0=1'b0; A1=1'b0;
#10 $finish;
end
endmodule
output [ 2 : 0 ] Dout;
input [ 7 : 0 ] Din;
reg [ 2 : 0 ] Dout;
always@(Din)
begin
case (Din)
8'b00000001:Dout = 3'b000;
8'b00000010:Dout = 3'b001;
8'b00000100:Dout = 3'b010;
8'b00001000:Dout = 3'b011;
8'b00010000:Dout = 3'b100;
8'b00100000:Dout = 3'b101;
8'b01000000:Dout = 3'b110;
8'b10000000:Dout = 3'b111;
default: Dout=3’bzzz;
endcase
end
endmodule
output [ 2 : 0 ] Dout;
input [ 7 : 0 ] Din;
reg [ 2 : 0 ] Dout;
always@(Din)
begin
casex(Din)
endcase
end
endmodule
OR
always @(Din)
begin
else Dout=3'd0;
end
endmodule
module mux8_1(Y,S,I);
output Y;
input [2:0]S;
input[7:0]I;
reg Y;
always@(S,I)
begin
case(S)
3'b000:Y=I[0];
3'b001:Y=I[1];
3'b010:Y=I[2];
3'b011:Y=I[3];
3'b100:Y=I[4];
3'b101:Y=I[5];
3'b110:Y=I[6];
3'b111:Y=I[7];
endcase
end
endmodule
or
module mux8_1(Y,S,I);
output Y;
input [2:0]S;
input[7:0]I;
reg Y;
always@(S,I)
begin
if (S==3'b000) Y=I[0];
else Y=3'dz;
end
endmodule
G0
module Binary_Gray_4(B,G);
output [3:0]G;
input [3:0]B;
assign G[3]=B[3];
Gray_bin_1 x1(G[2],G[3],B[2]);
endmodule
//Subprograms
module Gray_bin_1(b0,g1,g0);
output b0;
input g0,g1;
endmodule
input a, b,c;
assign sum= a ^ b ^ c;
endmodule
input a, b,c;
assign diff= a ^ b ^ c;
endmodule
module stimulus();
reg B[3:0];
wire G[3:0];
Binary_Gray_4 B1(B,G);
initial
begin
end
endmodule
input a, b,c;
assign sum= a ^ b ^ c;
assign yxor=a^b^c;
assign yxnor=~(a^b^c);
assign yand=a&b&c;
assign yor=a|b|c;
endmodule
Module stimulus();
reg A,B,C;
wire SUM,COUT,YXOR,YXNOR,YAND,YOR;
fulladder f1(SUM,COUT,YXOR,YXNOR,YAND,YOR,A,B,C);
initial
begin
A=1’b0;B=1’b0;C=1’b0;
#10 A=1’b0;B=1’b0,C=1’b0;
#10 A=1’b0;B=1’b0;C=1’b1;
#10 A=1’b0;B=1’b1;C=1’b0;
#10 A=1’b0;B=1’b1;C=1’b1;
#10 A=1=b1;B=1’b0;C=1’b0;
#10 A=1’b1;B=1’b0;C=1’b1;
#10 A=1’b1;B=1’b1;C=1’b0;
#10 A=1’b1;B=1’b1;C=1’b1;
#10 $finish;
Department of ETE, BIT,Bangalore Page 11
HDL MANUAL (18ECL58)
end
endmodule
input signed[31:0] A, B;
input Enable;
always@(Opcode,A,B,Enable)
begin
if(Enable==0)
Result=31'bx;
else
case(Opcode)
3'b000: Result=A+B;
3'b001: Result=A-B;
3'b010: Result=A+1;
3'b011: Result=A-1;
3'b100: Result=!A;
3'b101: Result=~A;
3'b110: Result=A|B;
3'b111: Result=A&B;
endcase
Result[32]=1'b1;
end
endmodule
module dff(q,qb,d,clk);
output q,qb;
input d,clk;
reg q=0,qb=1;
always@(posedge clk)
begin
q= d;
qb=~q;
end
endmodule
module srff(q,qb,sr,clk);
output q,qb;
input clk;
input[1:0]sr;
reg q=0,qb=1;
always@(posedge clk)
begin
case(sr)
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=1'bZ;
endcase
qb=~q;
end
endmodule
module jkff(q,qb,jk,clk);
output q,qb;
input clk;
input [1:0]jk;
reg q=0,qb=1;
always@(posedge clk)
begin
case (jk)
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=~q;
endcase
qb=~q;
end
endmodule
input clk,reset;
reg[3:0]count
always@(posedge clk)
begin
else
begin
count = count+1;
if(count==4’b1010)
count=4’b0000;
end
endmodule
output clk_2,clk_4,clk_8,clk_16;
input clk,reset;
reg clk_2,clk_4,clk_8,clk_16;
reg[3:0]count=4'b0000;
always@(posedge clk)
begin
if(reset==1)
begin
count = 4'b0000;
end else
begin
count = count+1;
Department of ETE, BIT,Bangalore Page 18
HDL MANUAL (18ECL58)
end
clk_2=count[0];
clk_4=count[1];
clk_8=count[2];
clk_16=count[3];
end
endmodule
end
endmodule