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

📄 ewcalc.asm

📁 简易的计算器,能进行加,减,乘,除等简单的运算!
💻 ASM
📖 第 1 页 / 共 5 页
字号:
               mov     edx,offset RNum10
              call     FloatToAscii
               jmp     FromSQ
         .endif

;--------[ Exponent functions ]-------------------------------------------
         .if eax == IDB_BUT2X || eax == IDB_BUT10X || eax == IDB_BUTEX && Buff != 0
             finit
              call     AsciiToFloat
               fld     RNum10
            .if eax == IDB_BUT2X
                  call     TwoX
            .elseif eax == IDB_BUT10X
                  call     TenX
            .elseif eax == IDB_BUTEX
                  call     ExpX
            .endif
               mov     edx,offset RNum10
              call     FloatToAscii
               jmp     FromSQ
         .endif

;--------[ Square root function ]-----------------------------------------
         .if eax == IDB_BUTSQ && Buff != 0
             finit
              call     AsciiToFloat
               fld     RNum10
             fsqrt
              fstp     RNum10
               mov     edx,offset RNum10
              call     FloatToAscii
               jmp     FromSQ
         .endif

;--------[ Hypotenuse function ]------------------------------------------
         .if eax == IDB_BUTHYP
              call     StoreCLR
               or      HPress, 1
               jmp     GetOut
         .endif
 
;--------[ Pecentage function ]-------------------------------------------
         .if eax == IDB_BUTPCT
             push      BPress
              and      BPress, 0
               or      BPress, 3
              call     Prep
            INVOKE     CopyMW, offset RH, offset PT, 12
            INVOKE     lstrcpy, ADDR PLBuff, ADDR HLBuff
            INVOKE     lstrcpy, ADDR PRBuff, ADDR HRBuff
              call     MulEM
              call     BaseToAscii
               and     BPress, 0
              call     StoreCLR
               mov     dword ptr Buff, 0031302eh
              call     AsciiToBase
              call     BaseToAscii
              call     Prep
                or     BPress, 3
              call     MulEM
              call     BaseToAscii
            INVOKE     SendMessage, hEdit, WM_SETTEXT, NULL, ADDR ConvO
            INVOKE     SendMessage, hEdit, EM_SETSEL, 33, 33

               pop     BPress
            .if BPress > 0
               INVOKE     CopyMW, offset PT, offset RH, 12
               INVOKE     lstrcpy, ADDR HLBuff, ADDR PLBuff
               INVOKE     lstrcpy, ADDR HRBuff, ADDR PRBuff
                  jmp     GetOut
            .endif
               jmp     GetOut
         .endif

;--------[ X to the 2 power function ]------------------------------------
         .if eax == IDB_BUTPOW && Buff != 0
            .if Float == 0
               INVOKE     lstrcpy, offset HLBuff, offset LBuff
               INVOKE     lstrcpy, offset HRBuff, offset RBuff
               INVOKE     CopyMW, offset PT, offset R, 12
               .if PT+36 > 0 || R+36 > 0
                     mov     BPress, 3
                    call     ShiftDec
                     jmp     EndIt
               .endif
                 call     Prep
                 call     MulMW
               INVOKE     CopyMW, offset R, offset R3, 4
                 call     BaseToAscii
                  jmp     EndIt
            .endif
             finit
              call     AsciiToFloat
               fld     RNum10
               fld     ST(0)
             fmulp     ST(1), ST(0)
              fstp     RNum10
               mov     edx,offset RNum10
              call     FloatToAscii
EndIt:
               jmp     FromSQ
         .endif

;--------[ X to the Nth power function ]----------------------------------
         .if eax == IDB_BUTXN
              call     StoreCLR
               or      NPress, 1
               jmp     GetOut
         .endif

;--------[reciprocal of 1 function ]--------------------------------------
         .if eax == IDB_BUTREC && Buff != 0
               mov     ConvH, 31h
               mov     HLBuff, 31h
               mov     HRBuff, 0
               mov     HLen, 0
            INVOKE     CLRMW, offset PT, 12
               mov     PT+12, 1
               mov     BPress, 4
               or      RPress, 1
              fld1
              fstp     RWrk10
               jmp     Continue
         .endif

;--------[ Plus or Minus ]--------------------------------------------------
         .if eax == IDB_BUTPM
            INVOKE     SendMessage, hEdit, WM_GETTEXT, 35, offset ConvO
            .if ConvO != 2dh
                  mov     word ptr ConvI, 002dh
               INVOKE     lstrcat, ADDR ConvI, ADDR ConvO
            .else
               INVOKE     lstrcpy, ADDR ConvI, ADDR ConvO + 1
            .endif
            .if ConvI+1 != 0
               INVOKE     lstrcpy, ADDR Buff, ADDR ConvI
                 call     AsciiToBase
               INVOKE     lstrcpy, ADDR Buff, ADDR ConvI
                 call     AsciiToFloat
            .endif
               INVOKE     SendMessage, hEdit, WM_SETTEXT, NULL, ADDR ConvI
                 call     Display
         .endif

;--------[ Addition function ]---------------------------------------------
         .if eax == IDB_BUTADD
            INVOKE     SendMessage, hOpr, WM_SETTEXT, NULL, ADDR PO
              call     StoreCLR
               mov     BPress, 1
               jmp     GetOut
         .endif

;--------[ Subtraction function ]------------------------------------------
         .if eax == IDB_BUTSUB
            INVOKE     SendMessage, hOpr, WM_SETTEXT, NULL, ADDR SO
              call     StoreCLR
               mov     BPress, 2
               jmp     GetOut
         .endif

;--------[ Multiply function ]---------------------------------------------
         .if eax == IDB_BUTMUL
            INVOKE     SendMessage, hOpr, WM_SETTEXT, NULL, ADDR MO
              call     StoreCLR
               mov     BPress, 3
               jmp     GetOut
         .endif

;--------[ Divide function ]-----------------------------------------------
         .if eax == IDB_BUTDIV
            INVOKE     SendMessage, hOpr, WM_SETTEXT, NULL, ADDR DO
              call     StoreCLR
               mov     BPress, 4
               jmp     GetOut
         .endif

;--------[ Equate function ]-----------------------------------------------
         .if eax == IDB_BUTEQ
            INVOKE     SendMessage, hOpr, WM_SETTEXT, NULL, ADDR EO
Continue:
            .if Float == 0          ; not floating point
                 call     Prep
               .if BPress == 1
                    call     AddEM  
                     jmp     FromSQ
               .elseif BPress == 2
                    call     SubEM
                     jmp     FromSQ
               .elseif BPress == 3
                    call     MulEM
                     jmp     FromSQ
               .elseif BPress == 4
                    call     DivEM
                     jmp     FromSQ
               .elseif NPress == 1
                  .if PT+36 == 0 && R+36 == 0 ; no decimals
                       call     PowerN
                        jmp     FromSQ
                  .else
                        jmp     FP
                  .endif
               .elseif HPress == 1
                     jmp     FP
               .else
                     jmp     GetOut
               .endif
            .endif    
FP:          finit
               fld     RNum10
               fld     RWrk10
            .if BPress == 1
                 fadd     ST(0), ST(1)
            .elseif BPress == 2
                 fsub     ST(0), ST(1)
            .elseif BPress == 3
                 fmul     ST(0), ST(1)
            .elseif BPress == 4 && R+12 > 0 || BPress == 4 && R+28 > 0
                 fdiv     ST(0), ST(1)
            .elseif NPress == 1
                 fld1
                 fxch
                fyl2x                         ; st(1) * log2(st(0)) 'alpha l not num 1'
                 fmul
                 call     TwoX
            .elseif HPress == 1
                  fld     RWrk10
                  fld     ST(0)                ; duplicate
                fmulP     ST(1), ST(0)
                 fstp     RWrk10
                  fld     RNum10
                  fld     ST(0)                ; duplicate
                fmulp     ST(1), ST(0)
                  fld     RWrk10
                 fadd     ST(0), ST(1)
                fsqrt
            .endif
              fstp     RNum10
               fld     RNum10
              fstp     RWrk10
StoreR:
               mov     edx, offset RNum10
              call     FloatToAscii

FromSQ:
            INVOKE     SendMessage, hEdit, WM_SETTEXT, NULL, ADDR ConvO
            INVOKE     SendMessage, hEdit, EM_SETSEL, 33, 33
               and     First, 0
               and     HPress, 0
               and     NPress, 0
               and     RPress, 0
               and     BPress, 0
               and     DP, 0
            INVOKE     SendMessage, hEdit, WM_GETTEXT, 34, offset Buff
            .if Buff == '*'
                  mov     Buff, 0
            .endif
              call     AsciiToBase
              call     BaseToAscii
              call     Display
            INVOKE     SendMessage, hEdit, WM_GETTEXT, 34, offset Buff ; for floating point ???
              call     AsciiToBase
              fldz
              fstp     RWrk10
              fldz
              fstp     RNum10
            INVOKE     SendMessage, hEdit, WM_GETTEXT, 34, offset Buff ; for floating point ???
              call     AsciiToFloat
               and     Min, 0
         .endif
pop     esi
pop     edi
      .endif
GetOut:
      INVOKE        CallWindowProc, SubTool, hwnd, wmsg, wparam, lparam
         RET
ToolbarProc   ENDP

;=========================================================================|
;                       Setup for addition routine.                       |
;=========================================================================|
AddEM   PROC
      .if Branch
            jmp     DoAdd
      .endif 
         mov     eax, PT+44
         mov     ebx, R+44
      .if eax != ebx                 ; signs not equal
          MOVmd     R5+32, PT+44 
            and     BPress, 0
            or      BPress, 2
            or      Branch, 1
           call     SubEM
            jmp     Exit
      .endif
DoAdd:
        call     AddMW
        call     BaseToAscii
         mov     eax, R+36
      .if eax > HLen
            mov     HLen, eax
      .endif
      INVOKE     lstrlen, offset RBuff
      .if eax > HLen && DecPos > 0
           call     Round
      .endif
         and     Branch, 0
Exit:
         RET
AddEM   ENDP

;=========================================================================|
;                      Setup for subtraction routine.                     |
;=========================================================================|
SubEM   PROC
      .if Branch
            jmp     DoSub
      .endif
         mov     eax, PT+44
         mov     ebx, R+44
      .if eax != ebx                 ; signs not equal
          MOVmd     R+44, R5+36
            or      Branch, 1
           call     AddEM
            jmp     Exit
      .endif
      .if R5+32 == 1
            and     R5+32, 0
      .else
            or      R5+32, 1
      .endif
DoSub:
         mov     eax, R+36           ; R+36 = length of dec num's cur
      .if eax > HLen                 ; HLen = length of dec num's prev
            mov     HLen, eax
      .endif
      INVOKE     lstrcmpi, offset HRBuff, offset RBuff
      .if eax == -1                  ; A < B
           call     Round
      .endif
       MOVmd     R+44, R5+32
        call     SubMW
        call     BaseToAscii
      INVOKE     lstrlen, offset RBuff
      .if HLen > eax && DecPos > 0
         INVOKE     lstrcpy, ADDR ConvO, ADDR LBuff
         INVOKE     lstrcat, ADDR ConvO, ADDR Period
         INVOKE     lstrcat, ADDR ConvO, ADDR Zero
         INVOKE     lstrcat, ADDR ConvO, ADDR RBuff
         INVOKE     lstrlen, offset LBuff+1
         INVOKE     lstrcpy, ADDR RBuff, ADDR ConvO[eax]    ; non decimal number
      .endif
         mov     BPress, 0
         and     Branch, 0
Exit:
         RET
SubEM   ENDP

;=========================================================================|
;                       Setup for  multiply routine.                      |
;=========================================================================|

⌨️ 快捷键说明

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