Professional Documents
Culture Documents
Coe118 Assgn Abstraction Level
Coe118 Assgn Abstraction Level
BEHAVIORAL LEVEL
module mux21_bh (din_0, din_0,s0, y);
input din_0;
input din_1;
input s0;
output y;
reg y;
wire s0;
always@(sel or din_0 or din_1)
begin
if(sel==1b0)
begin
y=din_0;
else
y=din_1;
end
end
endmodule
SWITCH LEVEL
module mux(out, in, sel);
output out;
input[1:0]in;
input sel;
wire sel_b;
supply1 pwr;
supply2 gnd;
pmos(sel_b, pwr, sel);
nmos(sel_b, gnd, sel);
cmos(out, in[0], sel_b, sel);
cmos(out, in[1], sel, sel_b);
endmodule
DATA FLOW
`resetall
`timescale 1ns/1ps
module mux41data (din,s,y);
input [0:3] din;
input[0:1]s;
output out;
assign out=din[s];
endmodule
BEHAVIORAL
`resetall
`timescale 1ns/1ps
module mux42beh(din, s0, s1, y);
input [0:3] din;
input s0;
input s1;
output y;
reg y;
wire s0,s1;
always@(s0 or s1) begin
case({s0,s1})
2'b00:y=din[0];
2'b01:y=din[1];
2'b10:y=din[2];
2'b11:y=din[3];
default:y=1'b1;
endcase
end
endmodule
DATA FLOW
`resetall`
timescale 1ns/1ps
module dec38data (a,b,c,dout);
input a,b,c;
output [0:7]dout;
assign dout[0]=(~a)&(~b)&(~c);
assign dout[1]=(~a)&(~b)&c;
assign dout[2]=(~a)&b&(~c);
assign
assign
assign
assign
assign
endmodule
dout[3]=(~a)&b&c;
dout[4]=a&(~b)&(~c);
dout[5]=a&(~b)&c;
dout[6]=a&b&(~c);
dout[7]=a&b&c;
BEHAVIORAL MODELING
`resetall`
timescale 1ns/1ps
module decoder38beh(a, b, c, y);
input a;
input b;
input c;
output [0:7] y;
reg [0:7]y;
// wire a,b,c;
always@(a or b or c)
begin
case({a,b,c})
3'b000:begin y=8'b10000000; end
3'b001:begin y=8'b01000000; end
3'b010:begin y=8'b00100000; end
3'b011:begin y=8'b00010000; end
3'b100:begin y=8'b00001000; end
3'b101:begin y=8'b00000100; end
3'b110:begin y=8'b00000010; end
3'b111:begin y=8'b00000001; end
default :begin y=8'b00000000; end
endcase
end
endmodule
DATA FLOW
module full_adder
(input a,
input b,
input c,
output sum,
output carry);
assign sum = a & ~b & ~c | ~a & b & ~c | ~a & ~b & c | a & b & c;
assign carry = a & b | a & c | b & c;
endmodule
6. 8-to-1 multiplexer
DATA FLOW
module mux81data1(s,din,y);
input [0:2]s;
input [0:7]din;
output y;wire [0:7]t;
assign t[0]=(~s[0])&(~s[1])&(~s[2]&i[0]);
assign t[1]=(~s[0])&(~s[1])&(s[2]&i[1]);
assign t[2]=(~s[0])&(s[1])&(~s[2]&i[2]);
assign
assign
assign
assign
assign
assign
endmodule
t[3]=(~s[0])&(s[1])&(s[2]&i[3]);
t[4]=(s[0])&(~s[1])&(~s[2]&i[4]);
t[5]=(s[0])&(~s[1])&(s[2]&i[5]);
t[6]=(s[0])&(s[1])&(~s[2]&i[6]);
t[7]=(s[0])&(s[1])&(s[2]&i[7]);
y=t[0]|t[1]|t[2]|t[3]|t[4]|t[5]|t[6]|t[7];
BEHAVIORAL
module mux81bh(i,s,o);
input [0:7]i;i
nput [0:2]s;
output o;
wire [0:7]i;
wire [0:2]s;
wire [0:7]y;
reg o;
always@(s)
begin
case(s)
3'b000: o=i[0];
3'b001: o=i[1];
3'b010: o=i[2];
3'b011: o=i[3];
3'b100: o=i[4];
3'b101: o=i[5];
3'b110: o=i[6];
3'b111: o=i[7];
endcase
end
endmodule
7. 4-to-2 line encoder
BEHAVIORAL
module encoder42beh(din,
input [0:3] din;
output a;
output b;
reg a;
reg b;
always@(din)
begin
case({din})
4'b1000:begin
4'b0100:begin
4'b0010:begin
a, b);
BEHAVIORAL
module encodr83bh (din,a,b,c);
input [0:7]din;
output a,b,c;
reg a,b,c;
always@(din)
begin
case(din)
8'b10000000:begin a=1'b0;b=1'b0,c=1'b0;end
8'b01000000:begin a=1'b0;b=1'b0;c=1'b1;end
8'b00100000:begin a=1'b0;b=1'b1;c=1'b0;end
8'b00010000:begin a=1'b0;b=1'b1;c=1'b1;end
8'b10001000:begin a=1'b1;b=1'b0,c=1'b0;end
8'b10000100:begin a=1'b1;b=1'b0,c=1'b1;end
8'b10000010:begin a=1'b1;b=1'b1,c=1'b0;end
8'b10000001:begin a=1'b1;b=1'b1,c=1'b1;end
default :begin a=1'bz;b=1'bz;c= 1'b1;end
endcase
end
9. Shift Register
BEHAVIORAL
module shiftReg
(input CLK,
input reset,
// initialize registers
input shift,
input [7:0] Din, // Data input for load
output [7:0] Dout);
reg [7:0] D0, D1, D2, D3;
assign Dout = D0;
always @(posedge CLK) begin
if (reset) begin
D0 <= 0; D1 <= 0; D2 <= 0; D3 <= 0;
end else if (shift) begin
D3 <= Din; D2 <= D3; D1 <= D2; D0 <= D1;
end
end
endmodule
BEHAVIORAL
module Decd2to4(i0, i1, out0, out1, out2, out3);
input i0;
input i1;
output out0;
output out1;
output out2;
output out3;
reg out0,out1,out2,out3;
always@(i0,i1)
case({i0,i1})
2'b00: {out0,out1,out2,out3}=4'b1000;
2'b01: {out0,out1,out2,out3}=4'b0100;
2'b10: {out0,out1,out2,out3}=4'b0010;
2'b11: {out0,out1,out2,out3}=4'b0001;
default: $display("Invalid");
endcase
endmodule
GATE LEVEL
module decoder_2x4_gates (D, A, B, enable);
output [0: 3] D;`
input A, B;
input enable;
wire A_not, B_not, enable_not;
not
G1
G2
G3
(A_not, A),
(B_not, B),
(enable_not, enable);
G4
G5
G6
G7
(D[0],
(D[1],
(D[2],
(D[3],
nand
endmodule