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

📄 vmlargeintmath.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    mov         eax,dword ptr [xResult].HighPart
    shr         eax,1Fh
    mov         ecx,dword ptr [dwTempOne]
    add         ecx,ecx
    or          eax,ecx
    mov         dword ptr [dwTempOne],eax
    mov         eax,dword ptr [xResult].HighPart
    add         eax,eax
    mov         ecx,dword ptr [xResult].LowPart
    shr         ecx,31
    or          eax,ecx
    mov         dword ptr [xResult].HighPart,eax
    shl         dword ptr [xResult].LowPart,1
    mov         eax,dword ptr [xDivisor].HighPart
    cmp         dword ptr [dwTempTwo],eax
    ja          label2

    mov         eax,dword ptr [xDivisor].HighPart
    cmp         dword ptr [dwTempTwo],eax
    jne         label4

    mov         eax,dword ptr [xDivisor].LowPart
    cmp         dword ptr [dwTempOne],eax
    jb          label4

    label2:

    or          dword ptr [xResult].LowPart,1
    sub         eax,eax
    sub         eax,dword ptr [xDivisor].HighPart
    neg         eax
    sub         dword ptr [dwTempTwo],eax
    mov         eax,dword ptr [xDivisor].LowPart
    cmp         dword ptr [dwTempOne],eax
    jae         label3

    dec         dword ptr [dwTempTwo]

    label3:

    sub         eax,eax
    sub         eax,dword ptr [xDivisor].LowPart
    neg         eax
    sub         dword ptr [dwTempOne],eax

    label4:   

    dec         dword ptr [dwCounter]
    cmp         dword ptr [dwCounter],0
    ja          label1

    cmp         dword ptr [pxRemainder],0
    je          label5

    mov         eax,dword ptr [dwTempOne]
    mov         ecx,dword ptr [dwTempTwo]
    mov         edx,dword ptr [pxRemainder]
    mov         dword ptr [edx],eax
    mov         dword ptr [edx+4],ecx

    label5:
  }

  return( xResult );
}
/* End of function "VMLargeIntDivide"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMLargeIntDivide

       DESCRIPTION:  perform a large integer divide operation

             INPUT:  xDividend - value to divide
                     ulDivisor - value to divide by
                     pulRemainder - pointer to a remainder value
            OUTPUT:  

           RETURNS:  LARGE_INTEGER - the quotient 
*/
LARGE_INTEGER VMLargeIntDivide( LARGE_INTEGER xDividend, ULONG ulDivisor, ULONG* pulRemainder )
{
  LARGE_INTEGER xResult;

  __asm
  {
    mov         eax,dword ptr [xDividend].LowPart
    mov         edx,dword ptr [xDividend].HighPart
    mov         ebx,dword ptr [ulDivisor]

    or          edx,edx
    jne         label1

    div         ebx
    mov         esi,edx
    xor         edx,edx
    
    jmp      label3

    label1:

    push        ebp

    mov         ecx,64
    xor         esi,esi

    label2:

    shl         eax,1
    rcl         edx,1
    rcl         esi,1
    sbb         edi,edi
    cmp         esi,ebx
    cmc
    sbb         ebp,ebp
    or          edi,ebp
    sub         eax,edi
    and         edi,ebx
    sub         esi,edi
    dec         ecx
    jne         label2

    pop         ebp

    label3:

    mov         [xResult].HighPart,edx
    mov         [xResult].LowPart,eax

    mov         ecx,[pulRemainder]
    or          ecx,ecx
    je          label4

    mov         dword ptr [ecx],esi

    label4:
  }

  return( xResult );
}
/* End of function "VMLargeIntDivide"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMLargeIntAdd

       DESCRIPTION:  add to large integers

             INPUT:  xValueOne - the first value
                     xValueTwo - the second value
            OUTPUT:  

           RETURNS:  LARGE_INTEGER  - the sum
*/
LARGE_INTEGER VMLargeIntAdd(LARGE_INTEGER xValueOne, LARGE_INTEGER xValueTwo )
{
  LARGE_INTEGER xResult;

  __asm
  {
    mov        eax,dword ptr [xValueOne].LowPart
    mov        edx,dword ptr [xValueOne].HighPart
    add        eax,dword ptr [xValueTwo].LowPart
    adc        edx,dword ptr [xValueTwo].HighPart
    mov        [xResult].LowPart,eax
    mov        [xResult].HighPart,edx
  }

  return( xResult );
}/* End of function "VMLargeIntAdd"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMLargeIntSubtract

       DESCRIPTION:  subtract a large integer from another

             INPUT:  xValueOne - the subtraend
                     xValueTwo - the subtractor
            OUTPUT:  

           RETURNS:  LARGE_INTEGER  - the difference
*/
LARGE_INTEGER VMLargeIntSubtract(LARGE_INTEGER xValueOne, LARGE_INTEGER xValueTwo )
{
  LARGE_INTEGER xResult;

  __asm
  {
    mov        eax,dword ptr [xValueOne].LowPart;
    mov        edx,dword ptr [xValueOne].HighPart;
    sub        eax,dword ptr [xValueTwo].LowPart;
    sbb        edx,dword ptr [xValueTwo].HighPart;
    mov        [xResult].LowPart,eax
    mov        [xResult].HighPart,edx
  }

  return( xResult );
}
/* End of function "VMLargeIntSubtract"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMLargeIntNegate

       DESCRIPTION:  negate a large integer value

             INPUT:  Value - value to negate
            OUTPUT:  none

           RETURNS:  LARGE_INTEGER  - negated value
*/
LARGE_INTEGER VMLargeIntNegate( LARGE_INTEGER xValue )
{
  LARGE_INTEGER xResult;

  __asm
  {
    mov         eax,dword ptr [xValue].LowPart
    mov         edx,dword ptr [xValue].HighPart
    neg         edx
    neg         eax
    sbb         edx,0
    mov         dword ptr [xResult].LowPart,eax
    mov         dword ptr [xResult].HighPart,edx
  }

  return( xResult );
}
/* End of function "VMLargeIntNegate"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMLargeIntAsString

       DESCRIPTION:  get a string value for a large integer

             INPUT:  pchBuffer - pointer to the output buffer
                     xValue - the value to print
            OUTPUT:  

           RETURNS:  pointer to buffer
*/
char* VMLargeIntAsString( char* pchBuffer, LARGE_INTEGER xValue )
{
  char* pchHead;
  char* pchTail;
  ULONG ulRemainder;
  char  chAChar;

  pchTail = pchBuffer;

  if ( VMLargeIntLessThanZero( xValue ) )
  {
    *pchTail++ = '-';
    xValue = VMLargeIntNegate( xValue );
  }

  pchHead = pchTail;

  do 
  {
    xValue = VMLargeIntDivide( xValue, 10, &ulRemainder );
    *pchTail++ = (char)ulRemainder + '0';
  }
  while ( VMLargeIntGreaterThanZero( xValue ) );
  
  *pchTail-- = 0;
  
  while ( pchHead < pchTail )
  {
    chAChar    = *pchHead;
    *pchHead++ = *pchTail;
    *pchTail-- = chAChar;
  }
  return( pchBuffer );
}
/* End of function "VMLargeIntAsString"
/*****************************************************************************/


/*****************************************************************************/
/* Check-in history */
/*
 *$Log:  $
*/
/*****************************************************************************/


⌨️ 快捷键说明

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