Monday, 7 November 2016

7. Verilog code for Half subtractor ( Different moduling style).

// Verilog code for Half Subtractor
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer:
//
// Create Date:    15:25:35 11/07/2016
// Designer Name:  Madhu Krishna
// Module Name:    half_sub
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module  half_sub( input_a,
                              input_b,
                           diff,
                           bo);

  // INPUTS
   input input_a;
input input_b;

  // OUTPUT
    output diff;
    output bo;

 //Declaration of Half_sub

   assign   diff = input_a ^ input_b;
   assign   bo   = (~(input_a) & input_b);
endmodule

-------------------------------------------------------------------------------------------------------------------------------------------


// Verilog code for Half Subtractor
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    15:43:44 11/07/2016 
// Designer Name:  Madhu Krishna
// Module Name:    half_sub_str 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module  half_sub_str( input_a,
                                    input_b,
                                diff,
                                bo);
  // INPUTS
    input   input_a;
    input   input_b;
 
  // OUTPUTS
    output  diff;
    output  bo;
    wire   con_lin;
 
  // NOT gate Instantiation Template
  not_gate_code U_NOT_GATE(
    .input_a(input_a), 
    .output_y(con_lin)
    );
  
  // XOR gate Instantiation Template  
  xor_gate_beh U_XOR_GATE (
    .input_a(input_a), 
    .input_b(input_b), 
    .output_y(diff)
    );

  // AND gate Instantiation Template 
  
  and_gate_code U_AND_GATE (
    .input_a(con_lin), 
    .input_b(input_b), 
    .output_y(bo)
    );
endmodule


-------------------------------------------------------------------------------------------------------------------------------------------------



// Verilog code Half subtractor
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    16:06:07 11/07/2016 
// Designer Name:  Madhu Krishna
// Module Name:    half_sub_beh 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module  half_sub_beh( input_a,
                                      input_b,
                                  diff,
                                  bo);
  // INPUTS
   input   input_a;
   input   input_b;
  // OUTPUTS
    output   diff;
    output   bo;
 
reg  diff;
reg  bo;
wire [1:0]con_out;
 
  // Declaration of half sub
  
     assign con_out = {input_a,input_b};
  
  always @(*) begin
    if(con_out == 2'b00) begin
  diff  <= 1'b0;
   bo   <= 1'b0;
  end else if(con_out == 2'b01) begin
         diff  <= 1'b1;
         bo    <= 1'b1;
   end else if(con_out == 2'b10)begin
        diff  <= 1'b1;
        bo    <= 1'b0;
    end else begin
        diff  <= 1'b0;
        bo    <= 1'b0;
    end
  end  
endmodule

------------------------------------------------------------------------------------------------------------------------------------------

// Verilog code for Half Subtractor
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    16:32:16 11/07/2016 
// Designer Name:  Madhu krishna
// Module Name:    half_sub_beh2 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module  half_sub_beh2( input_a,
                                        input_b,
diff,
 bo);
  // INPUTS
    input   input_a;
    input   input_b;
 
  // OUTPUTS
    output  diff;
    output  bo;
 
    reg diff;
    reg bo;
    wire [1:0]con_out;
 
  // Half subtractor code using case
    assign con_out = {input_a,input_b};
 
always @(*)begin
 
  case (con_out)
2'b00 : begin
 diff <= 1'b0;
 bo   <= 1'b0;
end
2'b01 : begin
 diff <= 1'b1;
 bo   <= 1'b1;
end
2'b10 : begin
 diff <= 1'b1;
 bo   <= 1'b0;
end
2'b11 : begin
 diff <= 1'b0;
 bo   <= 1'b0;
  end
    endcase
end 
endmodule

-------------------------------------------------------------------------------------------------------------------------------------------


No comments:

Post a Comment