+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Newbie level 6
    Points: 233, Level: 2

    Join Date
    Jun 2018
    Posts
    14
    Helped
    0 / 0
    Points
    233
    Level
    2

    how to check a register value is 1 using verilog?

    I am writing verilog code for modular inversion algorithm, how write synthesizable verilog code to check a value inside the register is one(1) or not? kindly help on this.

    for example if register u=1, then it should return TRUE/some other operation to be continued else FALSE.
    how to do for this.

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 37,756, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,847
    Helped
    2012 / 2012
    Points
    37,756
    Level
    47

    Re: how to check a register value is 1 using verilog?

    pretty simple

    Code Verilog - [expand]
    1
    2
    3
    4
    5
    6
    
    if (u=1) begin
      // do something when u = 1
    end
    else begin
      // do something when u != 1
    end



  3. #3
    Newbie level 6
    Points: 233, Level: 2

    Join Date
    Jun 2018
    Posts
    14
    Helped
    0 / 0
    Points
    233
    Level
    2

    Re: how to check a register value is 1 using verilog?

    Quote Originally Posted by TrickyDicky View Post
    pretty simple

    Code Verilog - [expand]
    1
    2
    3
    4
    5
    6
    
    if (u=1) begin
      // do something when u = 1
    end
    else begin
      // do something when u != 1
    end
    Thank you for the reply. BTW, if u is a 16-bit register or more, can we follow the same method?
    Also i need this condition in a while loop but while is not sysnthesizable, how to proceed this.

    For example, So until if u!=1,it need to do some operation and when u become 1(u=1), it need to do some other operation.

    Can you suggest for this?
    Last edited by Poomagal; 30th April 2019 at 10:04.



  4. #4
    Advanced Member level 5
    Points: 37,756, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,847
    Helped
    2012 / 2012
    Points
    37,756
    Level
    47

    Re: how to check a register value is 1 using verilog?

    I suggest you read a verilog tutorial. There are plenty about. Remember, this is NOT software, but hardware. Before you write any code, you should have a circuit diagram of your intended circuit. Verilog is an HDL - hardware description language. How can you write the code if you dont know what circuit you're describing.



    •   AltAdvertisement

        
       

  5. #5
    Newbie level 6
    Points: 233, Level: 2

    Join Date
    Jun 2018
    Posts
    14
    Helped
    0 / 0
    Points
    233
    Level
    2

    Re: how to check a register value is 1 using verilog?

    Quote Originally Posted by TrickyDicky View Post
    I suggest you read a verilog tutorial. There are plenty about. Remember, this is NOT software, but hardware. Before you write any code, you should have a circuit diagram of your intended circuit. Verilog is an HDL - hardware description language. How can you write the code if you dont know what circuit you're describing.
    Yes I can understand, I have the algorithm, and i am reading and trying many tutorials to draw circuit diagram from the algorithm, so that only I can write the verilog code correctly. But I cannot get the clear idea of how to draw circuit diagram and write synthesizable verilog code from/for the given algorithm. Actually I am trying to write for extended euclidean algorithm.



  6. #6
    Super Moderator
    Points: 77,106, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,623
    Helped
    3560 / 3560
    Points
    77,106
    Level
    67

    Re: how to check a register value is 1 using verilog?

    Hi,

    the problem is that you are vague in informations.

    Give clear informations:
    Is it a 16 bit value or not?

    If 16 bit value:
    Then itīs range is 0..65535
    If you want to check for value 1 then you should draw the binary states of all 16 lines.
    (hint: 15 lines are LOW, one line is HIGH).

    then it should be obvious that you need to compare all the 16 lines for this state.
    Several ways to do this.
    * a 16 bit input AND logic gate with one input inverted
    * or a true 16bit + 16bit input comparator.

    Hand draw the circuit on a paper and you are done.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  7. #7
    Super Moderator
    Points: 259,331, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,282
    Helped
    13776 / 13776
    Points
    259,331
    Level
    100

    Re: how to check a register value is 1 using verilog?

    Some considerations regarding synthesis of recursive algorithms.

    Iteration loops are a means to describe parallel hardware. Respectively they can be only synthesized if the iteration count is known at compile time. A possible workaround is to implement the iteration for a known maximal iteration count and terminate the loop conditionally.

    Alternatively you can rewrite the loop as clocked sequential circuit, performing one iteration step per clock cycle.



  8. #8
    Full Member level 2
    Points: 1,038, Level: 7
    FlyingDutch's Avatar
    Join Date
    Dec 2017
    Location
    Bydgoszcz - Poland
    Posts
    131
    Helped
    20 / 20
    Points
    1,038
    Level
    7

    Re: how to check a register value is 1 using verilog?




  9. #9
    Super Moderator
    Points: 259,331, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,282
    Helped
    13776 / 13776
    Points
    259,331
    Level
    100

    Re: how to check a register value is 1 using verilog?

    Not sure how the link is related to the thread topic. A discussion about sequential implementation of recursive algorithms can be found e.g. here
    https://stackoverflow.com/questions/...rilog-possible



    •   AltAdvertisement

        
       

  10. #10
    Full Member level 2
    Points: 1,038, Level: 7
    FlyingDutch's Avatar
    Join Date
    Dec 2017
    Location
    Bydgoszcz - Poland
    Posts
    131
    Helped
    20 / 20
    Points
    1,038
    Level
    7

    Re: how to check a register value is 1 using verilog?

    Hi,

    I mean that "==" operator in case of registers is comparing them bit by bit (also "===" operator that aditionaly comparing bit by bit "x' and "z" states).

    Regards



--[[ ]]--