Skip to main content

Floating point addition 32 bit

// 32 bit  floating point  addition//

Author : Kishore Papisetty
HDl lagugage; verilog hdl

module fp_add_seq(sum,ready,a_original,b_original,start,clk);
   input [31:0] a_original, b_original;
   input        start, clk;
   output [31:0] sum;
   output        ready;

   reg           sumneg;
   reg [7:0]    sumexp;
   reg [22:0]    sumsig;
   assign  sum [31]    = sumneg;
   assign        sum [30:23] = sumexp;
   assign        sum [22:0]  = sumsig;

   reg [32:0]    a, b;
   reg [22:0]    asig, bsig;
   reg [7:0]    aexp, bexp;
   reg           aneg, bneg;
   reg [7:0]    diff;

   parameter     st_idle  = 0;
   parameter     st_cyc_1 = 1;
   parameter     st_cyc_2 = 2;
   parameter     st_cyc_3 = 3;

   reg [1:0]     state;

 

   assign ready = state == st_idle;

   always @( posedge clk )
     case( state )
       st_idle:
         if ( start ) begin
if ( a_original[30:23] < b_original[30:23] ) begin

               a = b_original;  b = a_original;

            end else begin

               a = a_original;  b = b_original;

            end

            state = st_cyc_1;

         end

       st_cyc_1:
         begin
aneg = a[31];     bneg = b[31];
            aexp = a[30:23];  bexp = b[30:23];
         
            asig = { 2'b0, aexp ? 1'b1 : 1'b0, a[22:0] };
            bsig = { 2'b0, bexp ? 1'b1 : 1'b0, b[22:0] };

            diff = aexp - bexp;
            bsig = bsig >> diff;
         
            state = st_cyc_2;

         end

       st_cyc_2:
         begin

            if ( aneg ) asig = -asig;
            if ( bneg ) bsig = -bsig;

            sumsig = asig + bsig;

            state = st_cyc_3;

         end

       st_cyc_3:
         begin
            sumneg = sumsig[22];
            if ( sumneg ) sumsig = -sumsig;

            if ( sumsig[21] )
begin
             

               sumexp = aexp + 1;
               sumsig = sumsig >> 1;

            end else if ( sumsig ) begin:A
             
               integer pos, adj, i;

             
               pos = 0;
               for (i = 22; i >= 0; i = i - 1 )
                 if ( !pos && sumsig[i] ) pos = i;

             
               adj = 23 - pos;
               if ( aexp < adj ) begin
                  sumexp = 0;
                  sumsig = 0;
                  sumneg = 0;

               end else begin
               

                  sumexp = aexp - adj;
                  sumsig = sumsig << adj;

               end

            end else begin
             
               sumexp = 0;
               sumsig = 0;

            end
end


           default: state = st_idle;

              endcase

endmodule

//test bench //


module faddition_tb;

// Inputs
reg [31:0] a_original;
reg [31:0] b_original;
reg start;
reg clk;

// Outputs
wire [31:0] sum;
wire ready;

// Instantiate the Unit Under Test (UUT)
fp_add_seq uut (
.sum(sum),
.ready(ready),
.a_original(a_original),
.b_original(b_original),
.start(start),
.clk(clk)
);

initial begin
// Initialize Inputs
a_original = 0;
b_original = 0;
start = 0;
clk = 0;

// Wait 100 ns for global reset to finish
#100;
        a_original = 32'b10010100101000000010001000100011;
b_original = 32'b00010010100000000001000000000000;
start = 1'b1;
// Add stimulus here

end
always #100 clk = !clk;

     
endmodule

Comments

Popular posts from this blog

FSM 101 in Mealy state

Author : Kishore Papisetty fsm style : mealy fsm verilog code for the sequence detector 101 in mealy state   module fsm_101(clk,rst,x,z); input clk,rst,x; output z; reg [1:0]pstate,nstate; reg z;   always@(x,pstate) case(pstate) 2'd0: if(x==1'd1) begin nstate<=2'd1; z<=1'd0; end else begin nstate<=2'd0; z<=1'd0; end 2'd1: if(x==1'd0) begin nstate<=2'd2; z<=1'd0; end else begin nstate<=2'd1; z<=1'd0; end 2'd2: if(x==1'd1) begin nstate<=2'd1; z<=1'd1; end else begin nstate<=2'd0; z<=1'd0; end endcase   always@(posedge clk) begin if(rst==1'd0) pstate<=2'd0; else pstate<=nstate; end   endmodule //TEST BENCH// `timescale 1ns / 1ps module fsm_tb; reg clk; reg rst; reg x; wire z; fsm_101 uut ( ...

JNTUA MTECH VLSI 2nd SEMESTER QUESTION PAPERS

VHDL code for a 3-bit binary to thermometer converter

Author : Kishore Papisetty Platform : Xilinx code : VHDL //bit binary to thermometer converter// library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; entity bin2therm2bit is                 port (                                 binary_input : in std_logic_vector (1 downto 0);                                 therm_output : out std_logic_vector (6 downto 0)                 ); end bin2therm6bit; architecture Behavioral of bin2therm6bit is begin                 process (binary_input)                 begin                                 label1 : case binary_inpu...