Page 275 - ARM 64 Bit Assembly Language
P. 275

264 Chapter 8


                6  #include <stdlib.h>
                7  #include <stdio.h>
                8  #include <string.h>
                9
                10  #define MAX_DECIMAL_DIGITS 16
                11  /* Multiply an unpacked BCD number by 2. Return 1 if there is a
                12   carry out of the most significant digit, or 0 otherwise.  The
                13   resulting number is returned in n1.
                14  */
                15  int base10double(char n1[MAX_DECIMAL_DIGITS])
                16  {
                17  int i, tmp, carry=0;
                18  for(i=0;i<MAX_DECIMAL_DIGITS;i++)
                19    {
                20      n1[i] += (n1[i] + carry);
                21      if(n1[i] > 9)
                22        {
                23          n1[i] -= 10;
                24          carry = 1;
                25        }
                26      else
                27        carry=0;
                28    }
                29  return carry;
                30  }
                31
                32  /* Convert a string into a signed fixed-point binary
                33   representation with up to 32 bits of fractional part.
                34  */
                35  int strtoSfixed(char *s, int frac_bits)
                36  {
                37  char *point = s;
                38  unsigned int value;
                39  int i,negative=0;
                40  char digits[MAX_DECIMAL_DIGITS];
                41  /* get the integer portion*/
                42  if(*s==’-’)
                43    {
                44      negative=1;
                45      s++;
                46    }
                47  value = atoi(s);
                48  /* find the decimal point */
                49  while((*point != ’.’)&&(*point != 0))
                50    point++;
                51  /* if there is nothing after the decimal point, or there is
                52     not a decimal point, then shift and return what we already
                53     have */
                54  if(( *point ==0)||(*(point+1) == 0 ))
   270   271   272   273   274   275   276   277   278   279   280