home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / platform / llshr.asm < prev    next >
Assembly Source File  |  1998-06-17  |  2KB  |  81 lines

  1.         title   llshr - long shift right
  2. ;***
  3. ;llshr.asm - long shift right
  4. ;
  5. ;       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  6. ;
  7. ;Purpose:
  8. ;       define signed long shift right routine
  9. ;           __allshr
  10. ;
  11. ;*******************************************************************************
  12.  
  13.  
  14. .xlist
  15. include cruntime.inc
  16. include mm.inc
  17. .list
  18.  
  19. ;***
  20. ;llshr - long shift right
  21. ;
  22. ;Purpose:
  23. ;       Does a signed Long Shift Right
  24. ;       Shifts a long right any number of bits.
  25. ;
  26. ;Entry:
  27. ;       EDX:EAX - long value to be shifted
  28. ;       CL    - number of bits to shift by
  29. ;
  30. ;Exit:
  31. ;       EDX:EAX - shifted value
  32. ;
  33. ;Uses:
  34. ;       CL is destroyed.
  35. ;
  36. ;Exceptions:
  37. ;
  38. ;*******************************************************************************
  39.  
  40.         CODESEG
  41.  
  42. _allshr PROC NEAR
  43.  
  44. ;
  45. ; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
  46. ; depends only on the high order bit of edx).
  47. ;
  48.         cmp     cl,64
  49.         jae     short RETSIGN
  50.  
  51. ;
  52. ; Handle shifts of between 0 and 31 bits
  53. ;
  54.         cmp     cl, 32
  55.         jae     short MORE32
  56.         shrd    eax,edx,cl
  57.         sar     edx,cl
  58.         ret
  59.  
  60. ;
  61. ; Handle shifts of between 32 and 63 bits
  62. ;
  63. MORE32:
  64.         mov     eax,edx
  65.         sar     edx,31
  66.         and     cl,31
  67.         sar     eax,cl
  68.         ret
  69.  
  70. ;
  71. ; Return double precision 0 or -1, depending on the sign of edx
  72. ;
  73. RETSIGN:
  74.         sar     edx,31
  75.         mov     eax,edx
  76.         ret
  77.  
  78. _allshr ENDP
  79.  
  80.         end
  81.