Division 64bit/32bit=32bit

Diese Seite gibt es auch in Deutsch.


Description:
When you call FDIV64 you should supply the lower 32 bit of the dividend in register r0, the higher 32 bit in register r1 and the divisor in register r2. No other registers are used. After calling FDIV64 you get the quotient in register r0 and the reminder in register r1. Very important: FDIV64 only works properly with unsigned integers, and the quotient must fit into 32 bit!

FDIV64 takes 520 bytes in memory. Execution time is independend from the operands always 131 cycles.


C prototypes:
typedef struct {
  unsigned int quot;
  unsigned int rem;
} udiv_t;

/* If you need quotient and reminder */
extern __value_in_regs udiv_t FDIV64(unsigned int dvd_lo,
                                     unsigned int dvd_hi,
                                     unsigned int dvs);

/* If you need only the quotient */
extern unsigned int FDIV64(unsigned int dvd_lo, unsigned int dvd_hi,
                           unsigned int dvs);


Assembler Sourcecode:
|FDIV64|

        adds    r0,r0,r0
        adc     r1,r1,r1
        
        GBLA    i
i       SETA    31
        WHILE   i >0
        
        cmp     r1,r2            ;Also die 4 Zeilen
        subcs   r1,r1,r2         ;31 mal wiederholen !
        adcs    r0,r0,r0
        adc     r1,r1,r1
        
i       SETA    i-1
        WEND
        
        cmp     r1,r2
        subcs   r1,r1,r2
        adcs    r0,r0,r0

        movs    pc,r14
        

And back!


People with the strong desire to send me an email should combine the three parts peter, peter-teichmann and de in a sensible way to get the address.