Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

verilog code for square of a number without using * operator

Status
Not open for further replies.

alangs

Member level 3
Joined
Feb 5, 2010
Messages
57
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
india
Activity points
1,681
can anybody tell me how i can calculate the square of a number without using * operator.plz give me the answer in verilog code by using for loop......
 

Re: verilog code for square of a number without using * oper

Algorithm is simple:

2^2 = 2+2 = 4

3^2 = 3+3+3 = 9

4^2 = 4+4+4+4 = 16

5^2 = 5+5+5+5+5 = 25

C code:
Code:
int square(int x)
{
      int sum = 0;

      for(int count = x; count>0; count--)
      {
         sum = sum + x;
      }

      return sum;

}

Translate into your preferred HDL.
 

Re: verilog code for square of a number without using * oper

Hello,

It is better to use a multiplierso that you use combinational logic. However, if you like to use pipelining in your "square" circuit, you should write code for something like the diagram below. Note that this is a vaiable delay circuit, which means that you'll wait for 10^2 longer than 5^2



Best Wishes,
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top