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.

an 8-bit real number calculator with Verilog

Status
Not open for further replies.

SaadGhamdi

Newbie level 3
Joined
Dec 23, 2016
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
39
any help with an 8-bit real number calculator with Verilog?

hi guys,

I need to write a code of a calculator that divide two 8-bit binary numbers, the first 4 bits of each number represent the integer part and the second 4 bits represent the fraction part.

I don't know much about coding in Verilog, please help me with the code. :sad:


I really appreciate it.
regards,
 

start with the integer part. it is easy enough that you can learn verilog at the same time. no one here is going to write any code for you, you have to come up with something on your own.
 

Re: any help with an 8-bit real number calculator with Verilog?

hi guys,

I need to write a code of a calculator that divide two 8-bit binary numbers, the first 4 bits of each number represent the integer part and the second 4 bits represent the fraction part.

I don't know much about coding in Verilog, please help me with the code. :sad:


I really appreciate it.
regards,

hi,

check "restoring or non restoring" algorithm. both are good which use simple addition, subtraction and shifting operation.
understand the algorithm first and then design it

regards
 

I don't know much about coding in Verilog, please help me with the code.
You should develop your Verilog skills first. Start with simple RTL coding such as an up-down counter. After you are somewhat confident, move to tackle the next problem.

I need to write a code of a calculator that divide two 8-bit binary numbers, the first 4 bits of each number represent the integer part and the second 4 bits represent the fraction part.
There are various algos to do division in hardware. The simplest one is to use shift operators. Choose the one that best suits your needs and then implement it in Verilog RTL.

What is written in #2 is always valid. No one here will just give you the RTL code. But people are always here to help.
 

thank you for replying,

I forgot to add something, my code deals with BCD, and the user will enter the numbers with FRACTION part as binary, I already coded a module to take care of converting to BCD.

my question is "Is there an algorithm that can divide the number including the FRACTION part? or do I have to follow two algos one for the integer part and the other one for the fractional part?".
 

Hi,

Imagine an integer decimal number, lets say 864.
Now divide it by another integer decimal number. Let's say 12
The result is 72.

*****
Now assume it is not integer 864, but a fractional. Let's say 8.64 ( the decimal point is two digits shift left)
Divide it again by 12.
The result is 0.72.... (again the decimal point is two digits shift left)

--> just calculate if there is no decimal point and after that set the decimal point to the correct position.

--> the same is with binary division.

Klaus
 

Re: any help with an 8-bit real number calculator with Verilog?

I need to write a code of a calculator that divide two 8-bit binary numbers, the first 4 bits of each number represent the integer part and the second 4 bits represent the fraction part...

Consider the mantissa (it is not called the integer part): this is usually stored as two's complement signed normalized fraction (the decimal point is always implicit and at the leftmost position). Out of the four bits, one bit goes for the sign and the remaining 3 bits (max unsigned value of 7) can be used to represent -8 to +7. I guess you will be happy with the resolution.

The exponent is also signed integer but with an offset. It will have value of 0-15.

Addition, subtraction, multiplication and divisions of real numbers are done in software.
 
Last edited:

@c_mitra, that applies for floating point based representation. The OP described a fixed point representation.


In either case, the division part would be the same as normal with the location of the decimal point after division being the difference. Assuming unsigned, the maximum value would be 15.9375, and the minimum non-zero value would be 0.0625. The largest valid value after division would be 255. As with normal division, the result might not be representable in binary. eg, 1.0 / 7.0

After normal division, the upper 8b become the integer portion. The remaining bits are the fractional part, rounded down.

for example, 7.125 / 0.25 would look like 0111.0010 / 0000.0100 = 00011100.10000000....
 

Assuming unsigned, the maximum value would be 15.9375, and the minimum non-zero value would be 0.0625. ....

I cannot figure out how .9375 can be represented in 4 bits. The max value in 4 bits in binary will be 1111 and converted to decimal that will be 1*(2^-1)+1*(2^-2)+1*(2^-3)+1*(2^-4)=1/2+1/4+1/8+1/16=0.5+0.25+0.125+0.0625

It will be easier to calculate in hex: F*(2^-4)=15/16.

What you say can be very easily done by multiplying each number by 16 (that will make the numbers normal integers) and do the arithmetic and then take care of the factor of 16.
 

0.5 + 0.25 + 0.125 + 0.0625 = 0.9375


and yes, the math is done the same as normal integer math. The only difference is a constant (power of two) scaling factor.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top