home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC.ZIP / ABS.CAS next >
Encoding:
Text File  |  1992-06-10  |  1.1 KB  |  45 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - abs.cas
  3.  *
  4.  * function(s)
  5.  *        abs - absolute value
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <stdlib.h>
  19.  
  20. #undef abs              /* abs is defined as a macro in stdlib.h */
  21.  
  22. /*------------------------------------------------------------------------*
  23.  
  24. Name            abs - absolute value
  25.  
  26. Usage           int abs(int i);
  27.  
  28. Prototype in    stdlib.h
  29.  
  30. Description     abs returns the absolute value of the integer argument i
  31.  
  32. Return value    Integer value in  the range 0 to 32767,  with the exception
  33.                 that an argument of -32768 is returned as -32768.
  34.  
  35. *--------------------------------------------------------------------------*/
  36. int _CType abs(int i)
  37. {
  38. asm     mov     ax, i
  39. asm     or      ax, ax
  40. asm     jge     exit
  41. asm     neg     ax
  42. exit:
  43.         return _AX;
  44. }
  45.