home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / roots02.zip / ROOT22.ASM < prev    next >
Assembly Source File  |  1994-09-18  |  935b  |  45 lines

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