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

📄 gcc386.mcs

📁 大数运算库miracl。有了miracl这样的函数库
💻 MCS
字号:
; MCS file for Gnu GCC 80386-Pentium compiler
;
; Sorry about all the %'s! Each % must be input here as %%
; Triple register is cl|edi|ebp
; MUL_START. Initialise registers. Make ebx and esi point to multipliers a 
; and b. edi points at result c. Note edi is shared.
; Initialise Triple register to 0
; See makemcs.txt for more information about this file
; 
MACRO MUL_START
  ASM ("
  pushl %%%%ebp\n
  pushl %%%%edi\n
  pushl %%%%esi\n
  movl %%0,%%%%ebx\n
  movl %%1,%%%%esi\n
  movl %%2,%%%%edi\n
  pushl %%%%edi\n
  xorl %%%%ecx,%%%%ecx\n
  xorl %%%%edi,%%%%edi\n
  xorl %%%%ebp,%%%%ebp\n
ENDM
;
; STEP macro. Calculates a double-register partial product
; and adds it to the triple register total
; Parameters 1 & 2: Indices i and j for partial product multipliers a[i] 
; and b[j]
MACRO STEP
  movl 4*%d(%%%%ebx),%%%%eax\n
  mull 4*%d(%%%%esi)\n
  addl %%%%eax,%%%%ebp\n
  adcl %%%%edx,%%%%edi\n
  adc %%%%ch,%%%%cl\n
ENDM
;
; LAST
;
MACRO LAST
  movl 4*%d(%%%%ebx),%%%%eax\n
  mull 4*%d(%%%%esi)\n
  addl %%%%eax,%%%%ebp\n
ENDM
;
; MFIN macro. Finish column calculation. Store Sum for this column
; and get Carry for next
; Parameter 1: Index k for Column Sum c[k]
MACRO MFIN
  movl %%%%edi,%%%%edx\n
  popl %%%%edi\n
  movl %%%%ebp,4*%d(%%%%edi)\n
  pushl %%%%edi\n
  movl %%%%edx,%%%%ebp\n
  movl %%%%ecx,%%%%edi\n
  xor %%%%cl,%%%%cl\n
ENDM
;
; MUL_END
; Parameter 1: Index for final carry c[.]
MACRO MUL_END  
  popl %%%%edi\n
  movl %%%%ebp,4*%d(%%%%edi)\n
  popl %%%%esi\n
  popl %%%%edi\n
  popl %%%%ebp\n
  "
   :
   :"m"(a),"m"(b),"m"(c)
   :"eax","edi","esi","ebx","ecx","edx","ebp","memory"
  );
ENDM
;
; SQR_START
; 
MACRO SQR_START
  ASM ("
  pushl %%%%ebp\n
  pushl %%%%edi\n
  pushl %%%%esi\n
  movl %%0,%%%%ebx\n
  movl %%1,%%%%esi\n
  xorl %%%%ecx,%%%%ecx\n
  xorl %%%%edi,%%%%edi\n
  xorl %%%%ebp,%%%%ebp\n
ENDM
;
; DSTEP macro. Calculates a double-register partial product
; and add it twice to a triple register total
; Parameters 1 & 2 : Indices of partial product multipliers
MACRO DSTEP
  movl 4*%d(%%%%ebx),%%%%eax\n
  mull 4*%d(%%%%ebx)\n
  addl %%%%eax,%%%%ebp\n
  adcl %%%%edx,%%%%edi\n
  adc  %%%%ch,%%%%cl\n
  addl %%%%eax,%%%%ebp\n
  adcl %%%%edx,%%%%edi\n
  adc  %%%%ch,%%%%cl\n
ENDM
;
; SELF macro. Calculate the double-register square and
; add it to a triple register total
; Parameter 1 : Index of diagonal element
MACRO SELF
  movl 4*%d(%%%%ebx),%%%%eax\n
  mull %%%%eax\n
  addl %%%%eax,%%%%ebp\n
  adcl %%%%edx,%%%%edi\n
  adc  %%%%ch,%%%%cl\n
ENDM
;
; SFIN macro. Finish column calculation for squaring. Store Sum
; and get Carry for next column.
; Parameter 1: Index of Column Sum
MACRO SFIN
  movl %%%%ebp,4*%d(%%%%esi)\n
  movl %%%%edi,%%%%ebp\n
  movl %%%%ecx,%%%%edi\n
  xor  %%%%cl,%%%%cl\n
ENDM
;
; SQR_END
; Parameter 1: Index for final carry
MACRO SQR_END
  movl %%%%ebp,4*%d(%%%%esi)\n
  popl %%%%esi\n
  popl %%%%edi\n
  popl %%%%ebp\n
  "
   :
   :"m"(a),"m"(c)
   :"eax","edi","esi","ebx","ecx","edx","ebp","memory"
  );
ENDM
;
; REDC_START
;
MACRO REDC_START
  ASM ("
  pushl %%%%ebp\n
  pushl %%%%edi\n
  pushl %%%%esi\n
  movl %%0,%%%%ebx\n
  movl %%1,%%%%esi\n
  movl %%2,%%%%edx\n
  pushl %%%%edx\n
  xorl %%%%edi,%%%%edi\n
  xorl %%%%ecx,%%%%ecx\n
  movl (%%%%ebx),%%%%ebp\n
ENDM
;
; RFINU macro
;
MACRO RFINU
  movl %%%%ebp,%%%%eax\n
  popl %%%%edx\n
  pushl %%%%edx\n
  mull %%%%edx\n
  movl %%%%eax,4*%d(%%%%ebx)\n
  mull (%%%%esi)\n
  addl %%%%eax,%%%%ebp\n
  adcl %%%%edx,%%%%edi\n
  adc  %%%%ch,%%%%cl\n
  movl %%%%edi,%%%%ebp\n
  movl %%%%ecx,%%%%edi\n
  xorl %%%%ecx,%%%%ecx\n
  addl 4*(%d+1)(%%%%ebx),%%%%ebp\n
  adcl %%%%ecx,%%%%edi\n
ENDM
;
; RFIND macro
;
MACRO RFIND
  movl %%%%ebp,4*%d(%%%%ebx)\n
  movl %%%%edi,%%%%ebp\n
  movl %%%%ecx,%%%%edi\n
  xorl %%%%ecx,%%%%ecx\n
  addl 4*(%d+1)(%%%%ebx),%%%%ebp\n
  adcl %%%%ecx,%%%%edi\n
ENDM
;
; REDC_END
;
MACRO REDC_END
  movl %%%%ebp,4*%d(%%%%ebx)\n
  movl %%%%edi,4*(%d+1)(%%%%ebx)\n
  popl %%%%edx\n
  popl %%%%esi\n
  popl %%%%edi\n
  popl %%%%ebp\n
  "
   :
   :"m"(a),"m"(b),"m"(ndash)
   :"eax","edi","esi","ebx","ecx","edx","ebp","memory"
  );
ENDM
;
; ADD_START macro - initialise for add. Do first one
;
MACRO ADD_START
  ASM ("
  pushl %%%%esi\n
  pushl %%%%edi\n
  movl %%0,%%%%esi\n
  movl %%1,%%%%ebx\n
  movl %%3,%%%%edi\n
  movl (%%%%esi),%%%%eax\n
  addl (%%%%ebx),%%%%eax\n
  movl %%%%eax,(%%%%edi)\n
ENDM
;
; ADD macro. Add two numbers from memory and store result in memory.
; Don't forget carry bit
;
MACRO ADD
  movl 4*%d(%%%%esi),%%%%eax\n
  adcl 4*%d(%%%%ebx),%%%%eax\n
  movl %%%%eax,4*%d(%%%%edi)\n
ENDM
;
; ADD_END macro. Catch Carry
;
MACRO ADD_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  popl %%%%esi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c)
   :"eax","edi","esi","ebx","memory"
  );
ENDM
;
; INC_START macro
;
MACRO INC_START
  ASM ("
  pushl %%%%edi\n
  movl %%0,%%%%edi\n
  movl %%1,%%%%ebx\n
  movl (%%%%ebx),%%%%eax\n
  addl %%%%eax,(%%%%edi)\n
ENDM
;
; INC macro. Increment number in memory. Don't forget carry
;
MACRO INC
  movl 4*%d(%%%%ebx),%%%%eax\n
  adcl %%%%eax,4*%d(%%%%edi)\n
ENDM
;
; INC_END macro. Catch Carry
;
MACRO INC_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry)
   :"eax","edi","ebx","memory"
  );
ENDM
;
; SUB_START macro. Do first one.
;
MACRO SUB_START
  ASM ("
  pushl %%%%esi\n
  pushl %%%%edi\n
  movl %%0,%%%%esi\n
  movl %%1,%%%%ebx\n
  movl %%3,%%%%edi\n
  movl (%%%%esi),%%%%eax\n
  subl (%%%%ebx),%%%%eax\n
  movl %%%%eax,(%%%%edi)\n
ENDM
;
; SUB macro. Subtract two numbers in memory and store result in memory.
;
MACRO SUB
  movl 4*%d(%%%%esi),%%%%eax\n
  sbbl 4*%d(%%%%ebx),%%%%eax\n
  movl %%%%eax,4*%d(%%%%edi)\n
ENDM
;
; SUB_END macro. Catch Carry
;
MACRO SUB_END  
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  popl %%%%esi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c)
   :"eax","edi","esi","ebx","memory"
  );
ENDM
;
; DEC_START macro. Do first one.
;
MACRO DEC_START
  ASM ("
  pushl %%%%edi\n
  movl %%0,%%%%edi\n
  movl %%1,%%%%ebx\n
  movl (%%%%ebx),%%%%eax\n
  subl %%%%eax,(%%%%edi)\n
ENDM
;
; DEC macro. Decrement from number in memory. Don't forget borrow.
;
MACRO DEC
  movl 4*%d(%%%%ebx),%%%%eax\n
  sbbl %%%%eax,4*%d(%%%%edi)\n
ENDM
;
; DEC_END macro
;
MACRO DEC_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry)
   :"eax","edi","ebx","memory"
  );
ENDM
;
; KADD_START macro
;
MACRO KADD_START
  ASM ("
  pushl %%%%esi\n
  pushl %%%%edi\n
  movl %%0,%%%%esi\n
  movl %%1,%%%%ebx\n
  movl %%3,%%%%edi\n
  movl %%4,%%%%ecx\n
  xorl %%%%eax,%%%%eax\n
  k%d:\n
ENDM
;
; KASL macro
;
MACRO KASL
  decl %%%%ecx\n  
  je k%d\n
  leal 4*%d(%%%%esi),%%%%esi\n
  leal 4*%d(%%%%ebx),%%%%ebx\n
  leal 4*%d(%%%%edi),%%%%edi\n
  jmp k%d\n
  k%d:\n
ENDM
;
; KADD_END  macro
;
MACRO KADD_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  popl %%%%esi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c),"m"(n)
   :"eax","edi","esi","ebx","ecx","memory"
  );
ENDM
;
; KINC_START macro. Zero carry flag. 
;
MACRO KINC_START
  ASM ("
  pushl %%%%edi\n
  movl %%0,%%%%edi\n
  movl %%1,%%%%ebx\n
  movl %%3,%%%%ecx\n
  xorl %%%%eax,%%%%eax\n
  k%d:\n
ENDM
;
; KIDL macro
;
MACRO KIDL
  decl %%%%ecx\n
  je k%d\n
  leal 4*%d(%%%%ebx),%%%%ebx\n
  leal 4*%d(%%%%edi),%%%%edi\n
  jmp k%d\n
  k%d:\n
ENDM
;
; KINC_END macro
;
MACRO KINC_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry),"m"(n)
   :"eax","edi","ebx","ecx","memory"
  );
ENDM
;
; KDEC_START macro
;
MACRO KDEC_START
  ASM ("
  pushl %%%%edi\n
  movl %%0,%%%%edi\n
  movl %%1,%%%%ebx\n
  movl %%3,%%%%ecx\n
  xorl %%%%eax,%%%%eax\n
  k%d:\n
ENDM
;
; KDEC_END macro
;
MACRO KDEC_END
  movl $0,%%%%eax\n
  adcl %%%%eax,%%%%eax\n
  movl %%%%eax,%%2\n
  popl %%%%edi\n
  "
   :
   :"m"(a),"m"(b),"m"(carry),"m"(n)
   :"eax","edi","ebx","ecx","memory"
  );
ENDM

⌨️ 快捷键说明

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