Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Motorola 6809, divison-routines anyone?

How can I do a division calculation on a Motorola 6809 Processor?
Does any one have any example code? or just an explanation how to do it?

Thank in advance.


  • blipblip Member Posts: 756
    All I can offer is an explaination, sorry:

    Divisions at their heart is just repeated subtraction used to see how many times one number fits into another and what's left over. To optimize that, use bit shifting to reduce the nubers so the computation time is reduced. Steps for signed division:

    1) Get the signs of both operands and negate them to make them positive if they're not already. XOR their signs together and store it for later (easiest by copying one operand to another register and XORing the other onto it).

    2) OR together both operands in a temporary register. Shift it right until bit0=0 and note the count. Then, shift both operands by that shift count (make sure a shift count of zero won't cause it to shift 256/65536 times or something!).

    3) Subtract the dividend (numerator) by the divisor (denominator) until the dividend's sign bit turns negative (on many CPUs, the carry flag is set when this happens) and don't forget to note the number of subtractions. Add the divisor and dividend and store it as the remainder and decrement the subtraction count (called the quotient).

    4) Negate the quotient if the XORed sign bit of both input operands done earlier is set.
  • mike84umike84u Member Posts: 1
    : As Blip stated, its a looping subtraction. dl'd a floating point package at home but can't find link. found this instead. use as example - its a 32 by 16 bit division routine. that ftp dir also has some floating point libraries.
  • peretperet Member Posts: 69
    This sort of basic arithmetic is becoming a lost art, but everyone should know how to do it. Here's a general method in plain English.

    ; Hard-way division, can be extended to any number of bits
    ; dividend / divisor = quotient, remainder
    ; Storage:
    ; (dividend), (divisor), (remainder)
    ; quotient overwrites (dividend)
    ; (remainder) is same size as (divisor)

    clear (remainder)
    load (counter) with dividend size in bits
    rotate (dividend) left thru carry - c

    The initial state of carry doesn't matter, because it's shifted out in the last step.

Sign In or Register to comment.