8

Click here to load reader

Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Embed Size (px)

Citation preview

Page 1: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Engineering 100Section 250

Combinational Logic -- Examples

9/13/2010

Page 2: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Truth table

A B C Out

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 3: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Truth table

A B C Out

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 4: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

NOT

module NOT( input wire A, output reg B);

always @* begin if (A == 1'b0) begin B = 1'b1; end else begin B = 1'b0; end end endmodule

Page 5: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

module RR_raise10(

input wire OSU,

input wire Bowl,

output reg raise1,

output reg raise0);

always @* begin

raise1 = 1'b0;

raise0 = 1'b0;

if (OSU == 1'b0 && Bowl == 1'b1) begin

raise1 = 1'b0;

raise0 = 1'b1;

end

else if (OSU == 1'b1 && Bowl == 1'b0) begin

raise1 = 1'b0;

raise0 = 1'b1;

end else if (OSU == 1'b1 && Bowl == 1'b1) begin

raise1 = 1'b1;

raise0 = 1'b1;

end

end

endmodule

Page 6: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

module add(

input wire [1:0] A,

input wire [1:0] B,

output reg [2:0] C);

always @* begin

C[2:0] = A[1:0] + B[1:0];

end

endmodule

Add

Page 7: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Bad Add module add( input wire [1:0] A, input wire [1:0] B, output reg [1:0] C);

always @* begin if ( A == 2'b00 && B == 2'b00) begin C = 3'b000; end else if ( A == 2'b00 && B == 2'b01) begin C = 3'b001; ... end else if ( A == 2'b11 && B == 2'b10) begin C = 3'b101; end else begin C = 3'b110; end endendmodule

Page 8: Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010

Truth table

A B C

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1