I have been trying to implement an assembly routine in MSP430 for division. I already got the code for the division from the Horner Division Algorithm. The problem is that I only got the integer part. How I can get the fractional part from a division? For example: 5/2 = 2.5. How do I get the 0.5 part?
Division Assembly in MSP430
assemblymsp430
Related Topic
- USB ground on MSP430 Launchpad interfering with Comparator_A input voltage
- Electronic – How to Calculate Basic Cycles in MSP430
- Electronic – MSP430 blinking led
- Configuring input on MSP430
- Assembly Jump Question (PC Offsets) – MSP430
- Electronic – trigger an ADC conversion through TA0 CCTL1 Output in the MSP430, but nothing is happening
- Electronic – Cortex M0 – Defining an interrupt routine in assembly
Best Answer
You should get the remainder.
To turn that into a fraction you first need to decide between fixed and floating point; and if fixed, how many fractional bits.
Fixed point is easy : if you decide you want 8 fractional bits, just divide 2^8 * remainder / denominator, and use the size of that operation's remainder to determine rounding.
In your example, that would give
(256 * 1) / 2 = 128 as your fractional part, i.e. 128 / 256 = 0.5
Or for 3 fractional (decimal) digits, just compute 10^3 * remainder / denominator.
For floating point you would use a floating point library; it's far too complex to seriously consider rolling your own.