Ed Jiang

division 32 bit by 16 bit

Discussion created by Ed Jiang on Jan 30, 2013
Latest reply on Mar 19, 2013 by bigmac

Hi,

 

Does anyone has the assembly code for dividing 32 bit by 16 bit, i.e., unsigned long x, unsigned int?

in Freescale intrinsic_math.asm, there is only 32 bit by 8 bit division, as follows.

 

Thanks

Ed

;/*****************************************************************************

;*

;* Module: unsigned int udiv32i8to16(unsigned long x, unsigned char y)

;*

;* Description:

;*     Unsigned integer dividing 32 bit by 8 bit from 16 bit Uword.

;*     The Result is saturated at 0xFFFF if overflow occures.

;*

;* Returns:   x/y

;* Returns:   Out3:Out2:Out1:Out0 = (x3:x2:x1:x0)/(y0) = x/y

;*

;* Arguments: y (in) L1->5,SP; L2->6,SP;

;*                   H1->3,SP; H2->4,SP;

;*            y (in) A

;*

;* Range Issues: None

;*

;* Special Issues: HCS08S -Cs08 Option backend. The result is saturated

;*

;*****************************************************************************/

udiv32i8to16:

        PSHA        ;

        TAX         ; y -> X

        TST 4,SP    ;

        BNE udiv32Sat

        LDA 5, SP

        PSHA

        PULH

        LDA 6, SP

        DIV         ;

        BCS udiv32Sat

        PSHA

        LDA 8, SP

        DIV

        TAX         ;z0 -> X

        PULH        ;z1 -> H

        PULA

        RTS

 

 

udiv32Sat:

        LDHX #0FFFFh

        PULA

        RTS

 

Outcomes