home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 031 / roots02.zip / ROOT32.ASM < prev    next >
Assembly Source File  |  1994-09-18  |  994b  |  50 lines

  1. ; Copyright (C) 1992-1994 by Celso Minnitti Jr. All Rights Reserved.
  2.  
  3. PUBLIC root32
  4.  
  5. _TEXT    segment byte public 'CODE'
  6.     assume cs:_TEXT, ds:_TEXT
  7. .386
  8.  
  9. ;**************************************************************************
  10. ;                 ROOT32
  11. ; enter:   EAX = 1 - 0FFC3B3C9h (4291015625=1625*1625*1625)
  12. ; return:  EAX = cubic root
  13. ;       EDX = reminder
  14. ;**************************************************************************
  15. root32        proc    near
  16.         push    ecx
  17.         push    ebx
  18.         push    esi
  19.  
  20.         xor    ecx,ecx
  21.         inc    cx
  22.         mov    edx,ecx
  23.         mov    ebx,ecx          ;ecx=edx=ebx=1
  24.         mov    esi,6
  25.  
  26. root32_loop:    cmp     edx,eax
  27.         je    short root32_ret
  28.         ja    short root32_ret0
  29.  
  30.         add    ebx,esi          ;ebx=7 ,19,37,61...
  31.         add    esi,6             ;esi=12,18,24,30...
  32.         add    edx,ebx          ;edx=8 ,27,64,125...
  33.         inc    ecx             ;ecx=2 , 3, 4, 5
  34.         jmp    root32_loop
  35.  
  36. root32_ret0:    dec    ecx
  37.         sub    edx,ebx
  38. root32_ret:    sub    edx,eax
  39.         neg    edx
  40.         mov    eax,ecx
  41.  
  42.         pop    esi
  43.         pop    ebx
  44.         pop    ecx
  45.         ret
  46. root32        endp
  47.  
  48. _TEXT    ends
  49. end
  50.