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.DQC
/
LONG1.DOC
Wrap
Text File
|
2000-06-30
|
5KB
|
121 lines
A Long Integer Package for BDS-C
Rob Shostak
August, 1982
This package adds long (32-bit) signed integer capability to BDS-C much
in the same spirit as Bob Mathias's floating point package. Addition,
subtraction, multiplication, division, and modulus routines are provided
as well as comparison, assignment, and various kinds of conversion.
Each long integer is stored as an array of four characters. A long integer
x is thus declared by:
char x[4];
The internal representation is two's complement form, with the sign
(most significant) byte as the first byte of the array. For most
purposes, however, you needn't be concerned with the internal
representation.
Most of the routines that operate on longs take three arguments,
the first of which points to where the result is to be stored, and
the other two of which give the operands. For example, given
longs x, y, and z (all declared as char[4]),
ladd(z,x,y)
computes the sum of x and y and stores it into z, which
is returned as the value of the call. Note that the result
argument may legitimately be the same as one (or both) of the
operand arguments (for instance, ladd(x,x,x) does "the right thing").
The package is written partly in C and partly (for speed and
compactness) in 8080 assembly language. To use it, simply link
LONG.CRL into your program. A description is given below for
each routine.
ladd(r,op1,op2) Stores the sum of longs op1 and op2 into r, and
char r[4]; returns r. op1 or op2 may be used for r.
lsub(r,op1,op2) Similar to ladd but computes op1 - op2.
char r[4];
char op1[4],op2[4];
lmul(r,op1,op2) Similar to ladd but computes op1 * op2.
char r[4];
char op1[4],op2[4];
ldiv(r,op1,op2) Similar to ladd but computes the integer quotient
char r[4]; op1 / op2. If op2 is zero, zero is computed as the
char op1[4],op2[4]; result.
lmod(r,op1,op2) Similar to ladd but computes op1 mod op2. If op2
char r[4]; is zero, zero is computed as the result.
char op1[4],op2[4];
lcomp(op1,op2) Compares longs op1 and op2, and returns one of
char op1[4],op2[4]; (the ordinary integers) 1, 0, -1, depending on
whether op1 > op2, op1 = op2, or op1 < op2,
respectively.
lassign(dest,source) Assigns long source to long dest, and returns
char source[4],dest[4]; pointer to dest.
itol(l,i) Stores the long representation of the 16-bit
char l[4]; integer i into l, and returns l.
int i;
ltoi(l) Returns the integer representation of long l.
char l[4]; l must be representable as a 16-bit integer.
atol(l,s) Stores the long representation of the Ascii
char l[4]; string s into l, and returns l.
char s[]; The general form of s is a string of decimal digits,
possibly preceded by a minus sign, and terminated
by any non-digit.
ltoa(s,l) Stores the Ascii representation of long l into
char s[]; string s, and returns s. The representation
char l[4]; consists of a null-terminated string of Ascii
decimal digits, preceded by a minus sign if
l is negative. s must be large enough to receive
the conversion.
ltou(l) Converts long l to unsigned (by truncation).
char l[4]; l must be representable as a 16-bit unsigned
number. This function is identical in effect
with ltoi; the two may be used interchangably.
utol(l,u) Stores the long representation of unsigned
char l[4]; u in l, and returns pointer to l.
unsigned u;
Implementation Details:
Most of the work in the routines above is done by a single
8080 assembly-language function called long, the source for which
is found in the file LONG.CSM. The remainder of the package resides
in LONG.C. Note that most of the primitives described above simply
call long, passing it a function code (that tells it what operation
is to be performed) together with the arguments to be manipulated.
The file LONG.CRL contains both the assembled function long and the
compiled functions given in LONG.C. If you wish to make changes to
long, edit the file LONG.CSM, then reassemble it using the CASM
facility. Save the resulting .CRL image into some file other than
LONG.CRL (say LONG1.CRL), then use CLIB to transfer the new version
of long in LONG1.CRL to LONG.CRL. If you wish to change some of the
functions in LONG.C, first rename that file to LONG1.C, make the edits,
recompile, then use CLIB to transfer the new versions of the functions
you changed to LONG.CRL.