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

  1. ; Copyright (C) 1992-1994 by Celso Minnitti Jr. All Rights Reserved.
  2.  
  3. PUBLIC root26
  4.  
  5. _TEXT  segment byte public 'CODE'
  6.        assume cs:_TEXT, ds:_TEXT
  7.  
  8. ;**************************************************************************
  9. ;                 ROOT26
  10. ; enter:   AX = 1 - 0FE01h (65025=255*255)
  11. ; return:  AX = square root
  12. ;       DX = reminder
  13. ;**************************************************************************
  14. root26        proc    near
  15.         push    cx
  16.         push    bx
  17.  
  18.         mov    cx,1
  19.         mov    dx,cx
  20.         mov    bx,cx
  21. root26_loop:    cmp    dx,ax
  22.         je    root26_ret
  23.         ja    root26_ret0
  24.  
  25.         add    bx,2             ;bx=1,3,5,7 ,9 ,11,13...
  26.         add    dx,bx             ;dx=1,4,9,16,25,36,49...
  27.         inc    cx             ;cx=1,2,3,4 ,5 ,6, 7 ...
  28.         jmp    root26_loop
  29.  
  30. root26_ret0:    dec    cx
  31.         sub    dx,bx
  32. root26_ret:    sub    dx,ax
  33.         neg    dx
  34.         mov    ax,cx
  35.  
  36.         pop    bx
  37.         pop    cx
  38.         ret
  39. root26        endp
  40.  
  41. _TEXT    ends
  42. end
  43.