home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / H_LRSH.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-07  |  1.4 KB  |  49 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      H_LRSH.ASM -- long shift right                               |
  3. ;|                                                                   |
  4. ;|      Turbo-C Run Time Library        Version 3.0                  |
  5. ;|                                                                   |
  6. ;|      Copyright (c) 1987,1988,1990 by Borland International Inc.   |
  7. ;|      All Rights Reserved.                                         |
  8. ;[]-----------------------------------------------------------------[]
  9.  
  10.     INCLUDE    RULES.ASI
  11.  
  12. _TEXT    segment    public byte 'CODE'
  13.     assume    cs:_TEXT
  14.     public    LXRSH@
  15.     public    F_LXRSH@
  16.         public  N_LXRSH@
  17.  
  18. N_LXRSH@:
  19.         pop     bx                      ;fix up for far return
  20.         push    cs
  21.         push    bx
  22. LXRSH@:
  23. F_LXRSH@:
  24.     cmp    cl,16
  25.     jae    lsh@small
  26.     mov    bx,dx            ; save the high bits
  27.     shr    ax,cl            ; now shift each half
  28.     sar    dx,cl
  29. ;
  30. ;            We now have a hole in AX where the lower bits of
  31. ;            DX should have been shifted.  So we must take our
  32. ;            copy of DX and do a reverse shift to get the proper
  33. ;            bits to be or'ed into AX.
  34. ;
  35.     neg    cl
  36.     add    cl,16
  37.     shl    bx,cl
  38.     or    ax,bx
  39.         retf
  40. lsh@small:
  41.     sub    cl,16            ; for shifts more than 15, do this
  42.                     ; short sequence.
  43.         xchg    ax,dx                   ;
  44.     cwd                ; We have now done a shift by 16.
  45.     sar    ax,cl            ; Now shift the remainder.
  46.         retf
  47. _TEXT    ends
  48.     end
  49.