+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 1
    Points: 106, Level: 1

    Join Date
    Nov 2017
    Posts
    15
    Helped
    0 / 0
    Points
    106
    Level
    1

    Regarding Verilog codes

    Code Verilog - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    module fix(x,z,x1
        );
    input signed [4:0]x;
    output z;
    output signed[14:0]x1;
    localparam signed [11:0] y = 12'b100000000000;
    reg [14:0]z;
    always @* begin
     z=x*y;
    end
     
    // selecting msb 
    reg z1;
    always @* begin
       z1=x[4];
    end
     
    // to check if number is positive or negative  
    reg [14:0]x1;
    always @( z or z1)
    begin
      if (z1 == 1)
        x1 = ~z;
      else
        x1 = z;
    end
    endmodule

    this is the code to get one input .. can anyone help me in iterating this code so as to get 32 inputs... many thanks in advance....
    Last edited by bassa; 1st December 2017 at 08:16. Reason: add code tag

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 29,150, Level: 41
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,721
    Helped
    1604 / 1604
    Points
    29,150
    Level
    41

    Re: Regarding Verilog codes

    You don't iterate code (sounds like a sw coder writing verilog) you either use a generate-for loop or have an fsm that time shares a resource.

    Here is the format for a generate-for loop to create 32 instances of some block of code.
    Code Verilog - [expand]
    1
    2
    3
    4
    5
    
    generate
    genvar i;
    for (i=0;i<32;i=i+1) begin : gen_inputs
      // your code goes here
    end

    I'm not even sure what the point of this code is. A simple shift is all your really need here and an inversion (one's complement?) based on bit four of the input vector.

    This code doesn't look like it takes into account what hardware is generated from synthesis.



    •   AltAdvertisment

        
       

  3. #3
    Junior Member level 1
    Points: 106, Level: 1

    Join Date
    Nov 2017
    Posts
    15
    Helped
    0 / 0
    Points
    106
    Level
    1

    Re: Regarding Verilog codes

    thats the real to fixed point conversion codes



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 3
    Points: 5,356, Level: 17

    Join Date
    Feb 2015
    Posts
    887
    Helped
    256 / 256
    Points
    5,356
    Level
    17

    Re: Regarding Verilog codes

    This makes me question Verilog's aliasing rules. For example, z -- a 1 bit wire -- has the same name as z -- a 15 bit signed reg. Does verilog allow this and what does this mean?



  5. #5
    Super Moderator
    Points: 245,688, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    42,690
    Helped
    13008 / 13008
    Points
    245,688
    Level
    100

    Re: Regarding Verilog codes

    The declaration gives a vectored output z, both lines are combined. You probably get a compiler warning for the confused declaration.



    •   AltAdvertisment

        
       

  6. #6
    Advanced Member level 3
    Points: 5,356, Level: 17

    Join Date
    Feb 2015
    Posts
    887
    Helped
    256 / 256
    Points
    5,356
    Level
    17

    Re: Regarding Verilog codes

    This makes me wonder if there is a Verilog version of ioccc.



--[[ ]]--