home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-3 / LONG1.DOC < prev    next >
Text File  |  2000-06-30  |  5KB  |  121 lines

  1.            A Long Integer Package for BDS-C
  2.  
  3.           Rob Shostak
  4.               August, 1982
  5.  
  6. This package adds long (32-bit) signed integer capability to BDS-C much
  7. in the same spirit as Bob Mathias's floating point package.  Addition,
  8. subtraction, multiplication, division, and modulus routines are provided
  9. as well as comparison, assignment, and various kinds of conversion.
  10.  
  11. Each long integer is stored as an array of four characters.  A long integer
  12. x is thus declared by:
  13.  
  14.         char x[4];
  15.  
  16. The internal representation is two's complement form, with the sign
  17. (most significant) byte as the first byte of the array.  For most
  18. purposes, however, you needn't be concerned with the internal
  19. representation.
  20.  
  21. Most of the routines that operate on longs take three arguments,
  22. the first of which points to where the result is to be stored, and
  23. the other two of which give the operands.  For example, given
  24. longs x, y, and z (all declared as char[4]),
  25.  
  26.         ladd(z,x,y)
  27.  
  28. computes the sum of x and y and stores it into z, which 
  29. is returned as the value of the call. Note that the result
  30. argument may legitimately be the same as one (or both) of the
  31. operand arguments (for instance, ladd(x,x,x) does "the right thing").
  32.  
  33. The package is written partly in C and partly (for speed and
  34. compactness) in 8080 assembly language.  To use it, simply link
  35. LONG.CRL into your program.  A description is given below for
  36. each routine.
  37.  
  38.  
  39.  
  40. ladd(r,op1,op2)        Stores the sum of longs op1 and op2 into r, and
  41. char r[4];        returns r.  op1 or op2 may be used for r.
  42.  
  43.  
  44. lsub(r,op1,op2)        Similar to ladd but computes op1 - op2.
  45. char r[4];
  46. char op1[4],op2[4];
  47.  
  48. lmul(r,op1,op2)        Similar to ladd but computes op1 * op2.
  49. char r[4];
  50. char op1[4],op2[4];
  51.  
  52. ldiv(r,op1,op2)        Similar to ladd but computes the integer quotient
  53. char r[4];        op1 / op2.  If op2 is zero, zero is computed as the
  54. char op1[4],op2[4];    result.
  55.  
  56. lmod(r,op1,op2)        Similar to ladd but computes op1 mod op2.  If op2
  57. char r[4];        is zero, zero is computed as the result.
  58. char op1[4],op2[4];
  59.  
  60. lcomp(op1,op2)        Compares longs op1 and op2, and returns one of
  61. char op1[4],op2[4];    (the ordinary integers) 1, 0, -1, depending on
  62.             whether op1 > op2, op1 = op2, or op1 < op2,
  63.             respectively.
  64.  
  65. lassign(dest,source)    Assigns long source to long dest, and returns
  66. char source[4],dest[4];    pointer to dest.
  67.  
  68. itol(l,i)        Stores the long representation of the 16-bit
  69. char l[4];        integer i into l, and returns l.
  70. int i;
  71.  
  72. ltoi(l)            Returns the integer representation of long l.
  73. char l[4];        l must be representable as a 16-bit integer.
  74.  
  75. atol(l,s)        Stores the long representation of the Ascii
  76. char l[4];        string s into l, and returns l.
  77. char s[];            The general form of s is a string of decimal digits,
  78.                     possibly preceded by a minus sign, and terminated
  79.             by any non-digit.  
  80.  
  81. ltoa(s,l)        Stores the Ascii representation of long l into
  82. char s[];        string s, and returns s.  The representation
  83. char l[4];        consists of a null-terminated string of Ascii
  84.             decimal digits,    preceded by a minus sign if
  85.             l is negative.  s must be large enough to receive
  86.             the conversion.
  87.  
  88. ltou(l)            Converts long l to unsigned (by truncation).
  89. char l[4];        l must be representable as a 16-bit unsigned
  90.             number.  This function is identical in effect
  91.             with ltoi; the two may be used interchangably.
  92.  
  93.  
  94. utol(l,u)        Stores the long representation of unsigned
  95. char l[4];        u in l, and returns pointer to l.
  96. unsigned u;
  97.  
  98.  
  99.  
  100.  
  101. Implementation Details:
  102.  
  103. Most of the work in the routines above is done by a single 
  104. 8080 assembly-language function called long, the source for which
  105. is found in the file LONG.CSM.  The remainder of the package resides
  106. in LONG.C.  Note that most of the primitives described above simply
  107. call long, passing it a function code (that tells it what operation
  108. is to be performed) together with the arguments to be manipulated.
  109.  
  110. The file LONG.CRL contains both the assembled function long and the
  111. compiled functions given in LONG.C.  If you wish to make changes to
  112. long, edit the file LONG.CSM, then reassemble it using the CASM
  113. facility.  Save the resulting .CRL image into some file other than
  114. LONG.CRL (say LONG1.CRL), then use CLIB to transfer the new version
  115. of long in LONG1.CRL to LONG.CRL.  If you wish to change some of the
  116. functions in LONG.C, first rename that file to LONG1.C, make the edits,
  117. recompile, then use CLIB to transfer the new versions of the functions
  118. you changed to LONG.CRL.
  119.  
  120.  
  121.