📄 mrmuldv.any
字号:
long a,b,*c,*rp;
{
ASM mov eax,DWORD PTR a
ASM mul DWORD PTR b
ASM les bx,DWORD PTR c
ASM add eax,DWORD PTR es:[bx]
ASM adc edx,0h
ASM les si,DWORD PTR rp
ASM add eax,DWORD PTR es:[si]
ASM adc edx,0h
ASM mov DWORD PTR es:[si],eax
ASM les bx,DWORD PTR c
ASM mov DWORD PTR es:[bx],edx
}
***********************************************************************
/*
* Borland C++ 32-bit compiler (BCC32). Use with mirdef.h32
* Uses inline assembly feature. Suitable for Win32 Apps
* 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
*************************************************************************
/* GCC inline assembly version for Linux/DJGPP */
#include "miracl.h"
mr_small muldiv(mr_small a,mr_small b,mr_small c,mr_small m,mr_small *rp)
{
mr_small q;
__asm__ __volatile__ (
"movl %1,%%eax\n"
"mull %2\n"
"addl %3,%%eax\n"
"adcl $0,%%edx\n"
"divl %4\n"
"movl %5,%%ebx\n"
"movl %%edx,(%%ebx)\n"
"movl %%eax,%0\n"
: "=m"(q)
: "m"(a),"m"(b),"m"(c),"m"(m),"m"(rp)
: "eax","ebx","memory"
);
return q;
}
mr_small muldvm(mr_small a,mr_small c,mr_small m,mr_small *rp)
{
mr_small q;
__asm__ __volatile__ (
"movl %1,%%edx\n"
"movl %2,%%eax\n"
"divl %3\n"
"movl %4,%%ebx\n"
"movl %%edx,(%%ebx)\n"
"movl %%eax,%0\n"
: "=m"(q)
: "m"(a),"m"(c),"m"(m),"m"(rp)
: "eax","ebx","memory"
);
return q;
}
mr_small muldvd(mr_small a,mr_small b,mr_small c,mr_small *rp)
{
mr_small q;
__asm__ __volatile__ (
"movl %1,%%eax\n"
"mull %2\n"
"addl %3,%%eax\n"
"adcl $0,%%edx\n"
"movl %4,%%ebx\n"
"movl %%eax,(%%ebx)\n"
"movl %%edx,%0\n"
: "=m"(q)
: "m"(a),"m"(b),"m"(c),"m"(rp)
: "eax","ebx","memory"
);
return q;
}
void muldvd2(mr_small a,mr_small b,mr_small *c,mr_small *rp)
{
__asm__ __volatile__ (
"movl %0,%%eax\n"
"mull %1\n"
"movl %2,%%ebx\n"
"addl (%%ebx),%%eax\n"
"adcl $0,%%edx\n"
"movl %3,%%esi\n"
"addl (%%esi),%%eax\n"
"adcl $0,%%edx\n"
"movl %%eax,(%%esi)\n"
"movl %%edx,(%%ebx)\n"
:
: "m"(a),"m"(b),"m"(c),"m"(rp)
: "eax","ebx","esi","memory"
);
}
***********************************************************
;
; 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
*******************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -