1 /* bignum_copy.c - copy a bignum
2 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 * Copy a bignum from in to out.
26 * If the output is shorter than the input, copy lower-order littlenums.
27 * Return 0 or the number of significant littlenums dropped.
28 * Assumes littlenum arrays are densely packed: no unused chars between
29 * the littlenums. Uses memcpy() to move littlenums, and wants to
30 * know length (in chars) of the input bignum.
35 bignum_copy(in
, in_length
, out
, out_length
)
36 register LITTLENUM_TYPE
*in
;
37 register int in_length
; /* in sizeof(littlenum)s */
38 register LITTLENUM_TYPE
*out
;
39 register int out_length
; /* in sizeof(littlenum)s */
41 int significant_littlenums_dropped
;
43 if (out_length
< in_length
) {
44 LITTLENUM_TYPE
*p
; /* -> most significant (non-zero) input
47 memcpy((void *) out
, (void *) in
,
48 out_length
<< LITTLENUM_SHIFT
);
49 for (p
= in
+ in_length
- 1; p
>= in
; --p
) {
52 significant_littlenums_dropped
= p
- in
- in_length
+ 1;
54 if (significant_littlenums_dropped
< 0) {
55 significant_littlenums_dropped
= 0;
58 memcpy((char *) out
, (char *) in
,
59 in_length
<< LITTLENUM_SHIFT
);
61 if (out_length
> in_length
) {
62 memset((char *) (out
+ out_length
),
63 '\0', (out_length
- in_length
) << LITTLENUM_SHIFT
);
66 significant_littlenums_dropped
= 0;
69 return(significant_littlenums_dropped
);
72 /* end of bignum-copy.c */