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.

Division in MSP430 Assembly

Status
Not open for further replies.

empv

Newbie level 3
Joined
Nov 14, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
25
Hi, I've been trying to complete an assembly routine for division. This routine will allow only integer numbers as input. The problem I have is that the division in some operations will have an integer part and a fractional part. For example if I divide 10/3 = 3.333. How can I get the fractional part from that division?
 

Hi,

There are some solutions:

* In you example. .. When the "/3" = constant, then you could just multiply with "0.33333"

* if you need two fractional digits, then you could multiply the input value by 100.
Like instead of 10/3 ==> use (100 × 10) / 3 = 333. But place the decimal point after the second digit from right: 3.33

* or you can write your own division function. Maybe: 16 bit unsigned integer / 16 bit unsigned integer giving 32 bit unsigned integer (correct: 16 bit integer plus 16 bits fractional)

Decide what you want to do...

Klaus
 

Is there any algorithm for 16-bit division in assembly for the MSP430? I already wrote a code for 4-bit numbers in assembly. How can I extend that to 16-bits?
 

Hi,

MSP430 is a 16 bit controller... I wonder how you did the 4 bit division.
Where do you see the problem doing a 16 bit division, when you already did the 4 bit division?

I gave you some hints... You even did not say what input variable type you have and what output variable type.

In general a binary division is similar to a decimal division.
Shifting, deciding if the first value is bigger than the second, subtracting or not, result register update,...shifting...
It's almost the same for 4 bits, for 16 bits, for binary, for decimal....

Klaus
 

Are you considering such division intended to scale a variable value (numerator), or are both values variables (numerator, denominator) ? There are circumstances on which you can achieve a division just by using 1-multiply followed by few shift instructions.
 

Hi KlausST I wrote my own division function as you said and the input dividend and divisor are 16 bit unsigned numbers. I already implemented the restoring division algorithm and I extended it to 16 bits. Now my result is the format quotient and remainder. For example I divided 13/5 with my subroutine and the result is R4 = 0x0002 and R6 = 0x0003 with are registers in the MSP430 for storing the quotient and remainder respectively. All this was done in assembly language. Later on this result should be displayed in an LCD. The issue is that 13/5 = 2.6. How can I use the quotient and remainder such that the result that will be displayed in the LCD is 2.6? Thanks
 

Hi,

Let's use your example 13/5.
I wonder how you you achieved to get the result "2"....

For a 16 bit fractional result run a loop 16 times:

The remainder is 3.
[Shift remainder one bit left and get 6
Divide it by 5, result = 1 remainder = 1,
Shift the result left into the "fractional result" register f and get f= 0x0001 ]
Run all within the brackets 16 times.

loop2 is:
[Remainder shift gives 2
Divide by 5 gives result = 0, remainder = 2
Shift result in fraction reg. Gives 0x0002 ]

loop3 is:
[Remainder shift gives 4
Divide by 5 gives result = 0, remainder = 4
Shift result in fraction reg. Gives 0x0004 ]

loop4 is:
[Remainder shift gives 8
Divide by 5 gives result = 1, remainder = 3
Shift result in fraction reg. Gives 0x0005 ]

...This gives two results. One is the integer, one is the fractional.

****
But it seems you want a decimal result with one decimal digit like n your example "2.6"
The easiest way for this is to first multiply the first number with "10": 13 × 10 = 130.
Now divide it by 5 and get 26.
Now place the decimal point one digit from right: 26 --> 2.6
(For sure you need the bcd conversion first)

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top