⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mrmuldv.any

📁 miracl-大数运算库,大家使用有什么问题请多多提意见
💻 ANY
📖 第 1 页 / 共 5 页
字号:
 *  Also compatible with Microsoft Visual C++ 32-bit compiler
*/

#define ASM _asm

int muldiv(a,b,c,m,rp)
int a,b,c,m,*rp;
{
        ASM mov   eax,DWORD PTR a      
        ASM mul   DWORD PTR b          
        ASM add   eax,DWORD PTR c      
        ASM adc   edx,0h                 
        ASM div   DWORD PTR m          
        ASM mov   ebx,DWORD PTR rp     
        ASM mov   [ebx],edx              
}

int muldvm(a,c,m,rp)
int a,c,m,*rp;
{
        ASM mov   edx,DWORD PTR a      
        ASM mov   eax,DWORD PTR c      
        ASM div   DWORD PTR m          
        ASM mov   ebx,DWORD PTR rp     
        ASM mov   [ebx],edx              
}

int muldvd(a,b,c,rp)
int a,b,c,*rp;
{
        ASM mov   eax,DWORD PTR a      
        ASM mul   DWORD PTR b          
        ASM add   eax,DWORD PTR c      
        ASM adc   edx,0h                 
        ASM mov   ebx,DWORD PTR rp     
        ASM mov   [ebx],eax              
        ASM mov   eax,edx
}


void muldvd2(a,b,c,rp)
int a,b,*c,*rp;
{
        ASM mov   eax,DWORD PTR a      
        ASM mul   DWORD PTR b          
        ASM mov   ebx,DWORD PTR c
        ASM add   eax,[ebx]
        ASM adc   edx,0h
        ASM mov   esi,DWORD PTR rp
        ASM add   eax,[esi]
        ASM adc   edx,0h
        ASM mov   [esi],eax              
        ASM mov   [ebx],edx
}


*************************************************************************



/
/  Version for 32-bit Sun 386i Workstation
/
        .file   "mrmuldv.c"
        .version        "sun386-1.0"
        .text
        .globl  muldiv
muldiv:
        pushl   %ebp
        movl    %esp,%ebp

        movl    8(%ebp),%eax         /get a
        mull    12(%ebp)             /multiply by b
        addl    16(%ebp),%eax        /add c to low word
        adcl    $0,%edx              /add carry to high word

        divl    20(%ebp)             /divide by m 
        movl    24(%ebp),%ebx        /get address for remainder
        movl    %edx,(%ebx)          /store remainder

        popl    %ebp
        ret

        .text
        .globl  muldvm
muldvm:
        pushl   %ebp
        movl    %esp,%ebp

        movl    8(%ebp),%edx       /get a
        movl    12(%ebp),%eax      /add in c
        divl    16(%ebp)           /divide by m

        movl    20(%ebp),%ebx      /get address for remainder
        movl    %edx,(%ebx)        /store remainder

        popl    %ebp
        ret

        .text
        .globl  muldvd
muldvd:
        pushl   %ebp
        movl    %esp,%ebp

        movl    8(%ebp),%eax       /get a
        mull    12(%ebp)           /multiply by b
        addl    16(%ebp),%eax      /add c to low word
        adcl    $0,%edx            /add carry to high word
        movl    20(%ebp),%ebx      /get address for remainder
        movl    %eax,(%ebx)        /store remainder
        movl    %edx,%eax          /get quotient

        popl    %ebp
        ret


**************************************************************************


/
/ DJGPP GNU C version for DOS
/ M. Scott 22/3/98
/


        .file   "mrmuldv.c"
.text
.globl  _muldiv
_muldiv:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx


        movl    8(%ebp),%eax  
        mull    12(%ebp)      
        addl    16(%ebp),%eax 
        adcl    $0,%edx       

        divl    20(%ebp)       
        movl    24(%ebp),%ebx 
        movl    %edx,(%ebx)
    
        popl    %ebx
        popl    %ebp
        ret

        .globl  _muldvm
_muldvm:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx

        movl    8(%ebp),%edx  
        movl    12(%ebp),%eax 
        divl    16(%ebp)      

        movl    20(%ebp),%ebx 
        movl    %edx,(%ebx)   

        popl    %ebx
        popl    %ebp
        ret

        .globl  _muldvd
_muldvd:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx

        movl    8(%ebp),%eax  
        mull    12(%ebp)      
        addl    16(%ebp),%eax 
        adcl    $0,%edx       
        movl    20(%ebp),%ebx 
        movl    %eax,(%ebx)   
        movl    %edx,%eax     

        popl    %ebx
        popl    %ebp
        ret

        .globl  _muldvd2
_muldvd2:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx
        pushl   %esi

        movl    8(%ebp),%eax  
        mull    12(%ebp)
        movl    16(%ebp),%ebx
        addl    (%ebx),%eax
        adcl    $0,%edx       
        movl    20(%ebp),%esi
        addl    (%esi),%eax
        adcl    $0,%edx

        movl    %eax,(%esi)   
        movl    %edx,(%ebx)     

        popl    %esi
        popl    %ebx
        popl    %ebp
        ret


*************************************************************************

/
/ GNU C for Linux (and other 386 based Linux/Unix??) 
/
/

        .file   "mrmuldv.s"
.text
.globl  muldiv
muldiv:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx


        movl    8(%ebp),%eax  
        mull    12(%ebp)      
        addl    16(%ebp),%eax 
        adcl    $0,%edx       

        divl    20(%ebp)       
        movl    24(%ebp),%ebx 
        movl    %edx,(%ebx)
    
        popl    %ebx
        popl    %ebp
        ret

        .globl  muldvm
muldvm:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx

        movl    8(%ebp),%edx  
        movl    12(%ebp),%eax 
        divl    16(%ebp)      

        movl    20(%ebp),%ebx 
        movl    %edx,(%ebx)   

        popl    %ebx
        popl    %ebp
        ret

        .globl  muldvd
muldvd:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx

        movl    8(%ebp),%eax  
        mull    12(%ebp)      
        addl    16(%ebp),%eax 
        adcl    $0,%edx       
        movl    20(%ebp),%ebx 
        movl    %eax,(%ebx)   
        movl    %edx,%eax     

        popl    %ebx
        popl    %ebp
        ret

        .globl  muldvd2
muldvd2:
        pushl   %ebp
        movl    %esp,%ebp
        pushl   %ebx
        pushl   %esi

        movl    8(%ebp),%eax  
        mull    12(%ebp)
        movl    16(%ebp),%ebx
        addl    (%ebx),%eax
        adcl    $0,%edx       
        movl    20(%ebp),%esi
        addl    (%esi),%eax
        adcl    $0,%edx

        movl    %eax,(%esi)   
        movl    %edx,(%ebx)     

        popl    %esi
        popl    %ebx
        popl    %ebp
        ret


*************************************************************************


;
;  Watcom C/386 32-bit compiler V7.0. Use with mirdef.h32
;  Most parameters passed in registers
;  Written for Phar Lap 386ASM macro-assembler
;
;   V4.0 NOTE! Inline assembly versions of these routines, 
;   are also available. See miracl.h for details
;

        .386
        ASSUME CS:_TEXT
_TEXT   SEGMENT BYTE PUBLIC 'CODE'

        PUBLIC muldiv_
muldiv_ PROC NEAR

        mul     edx                 ;multiply a*b
        add     eax,ebx             ;add in c
        adc     edx,0               ;carry
        div     ecx                 ;divide by m
        mov     ebx,[esp+4]
        mov     [ebx],edx           ;remainder
        ret     4                   ;quotient in eax

muldiv_ endP

        PUBLIC muldvm_
muldvm_ PROC NEAR

        xchg    eax,edx       ;a*base+c
        div     ebx           ;divide by m
        mov     [ecx],edx     ;store remainder
        ret                   ;quotient in eax

muldvm_ endP

        PUBLIC muldvd_
muldvd_ PROC NEAR

        mul     edx           ;multiply a*b
        add     eax,ebx       ;add in c
        adc     edx,0
        mov     [ecx],eax     ;store remainder
        mov     eax,edx       ;get quotient
        ret                   ;quotient in eax

muldvd_ endP

_TEXT   ENDS
END


*******************************************************************


;
;  Zortech C/386 32-bit compiler V2.1
;  Use with mirdef.h32
;  Written for Phar lap 386ASM macro-assembler
;

        .386
        ASSUME CS:_TEXT
_TEXT   SEGMENT BYTE PUBLIC 'CODE'

        PUBLIC _muldiv
_muldiv PROC NEAR

        mov     eax,DWORD PTR [esp+4]
        mul     DWORD PTR [esp+8]
        add     eax,DWORD PTR [esp+12]
        adc     edx,0         
        div     DWORD PTR [esp+16]
        mov     ebx,DWORD PTR [esp+20]
        mov     [ebx],edx         
        ret

_muldiv endP

        PUBLIC _muldvm
_muldvm PROC NEAR

        mov     edx,DWORD PTR [esp+4]
        mov     eax,DWORD PTR [esp+8]
        div     DWORD PTR [esp+12]
        mov     ebx,DWORD PTR [esp+16]
        mov     [ebx],edx
        ret              

_muldvm endP

        PUBLIC _muldvd
_muldvd PROC NEAR

        mov     eax,DWORD PTR [esp+4]
        mul     DWORD PTR [esp+8]
        add     eax,DWORD PTR [esp+12]
        adc     edx,0
        mov     ebx,DWORD PTR [esp+16]
        mov     [ebx],eax
        mov     eax,edx
        ret        

_muldvd endP

_TEXT   ENDS
END



************************************************************************


unsigned int muldiv(a,b,c,m,rp)
unsigned int a,b,c,m,*rp;
{
    asm
    {
    ;
    ;  MACintosh version for Megamax or Lightspeed  Think C compiler
    ;  with 16-bit int, 68000 processor
    ;  For a 32 bit version for the 68020, see below 
    ;
        move   a(A6),D1      ;get a
        mulu   b(A6),D1      ;multiply by b
        clr.l  D0
        move   c(A6),D0      ;get c
        add.l  D0,D1         ;D1 contains a*b+c
        divu   m(A6),D1      ;divide by m
        move   D1,D0         ;return with quotient in D0
        swap   D1            ;get remainder
        move.l rp(A6),A0     ;get address for remainder
        move   D1,(A0)       ;store remainder
    }
}

unsigned int muldvm(a,c,m,rp)
unsigned int a,c,m,*rp;
{
    asm
    {
    ; 
    ; Version of muldvm for Apple MAC
    ;
        clr.l  D1
        move   a(A6),D1      ;get a
        swap   D1            ;move a to high word
        move   c(A6),D1      ;add in c
        divu   m(A6),D1      ;divide by m
        move   D1,D0         ;return quotient in D0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -