fixed_point.hcc


      //  fixed_point.hcc
      
      /*  Generates all combinations of signed and unsigned fixed point numbers
       *  with two integer bits and two fraction bits.  Match their values to
       *  integer two's complement and unsigned values.
       *
       *    C. Vickery
       *    Fall 2003
       */
      
      #include <fixed.hch>
      
      typedef FIXED_SIGNED( 2, 2 ) fixed_t;
      typedef FIXED_UNSIGNED( 2, 2 ) ufixed_t;
      typedef FIXED_UNSIGNED( 0, 0 ) fizzed_t;
      
      fixed_t   fixed_val;
      ufixed_t  ufixed_val;
      fizzed_t  fizzle;
      
      set clock = external "P1";
      
      void main(void)
      {
      
        //  Check handling of empty struct (non-zero values not allowed).
        fizzle = FixedLiteral(FIXED_ISUNSIGNED, 0, 0, 0.0 );
      
        //  Signed Values                              fixed pt      binary   int
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  0.00 ); //   00 00     0
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  0.25 ); //   00 01     1
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  0.50 ); //   00 10     2
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  0.75 ); //   00 11     3
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  1.00 ); //   01 00     4
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  1.25 ); //   01 01     5
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  1.50 ); //   01 10     6
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2,  1.75 ); //   01 11     7
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -2.00 ); //   10 00    -8
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -1.75 ); //   10 01    -7
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -1.50 ); //   10 10    -6
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -1.25 ); //   10 11    -5
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -1.00 ); //   11 00    -4
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -0.75 ); //   11 01    -3
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -0.50 ); //   11 10    -2
        fixed_val = FixedLiteral( FIXED_ISSIGNED, 2, 2, -0.25 ); //   11 11    -1
      
        //  Unsigned Values                               fixed pt      binary int
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  0.00 ); //   00 00   0
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  0.25 ); //   00 01   1
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  0.50 ); //   00 10   2
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  0.75 ); //   00 11   3
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  1.00 ); //   01 00   4
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  1.25 ); //   01 01   5
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  1.50 ); //   01 10   6
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  1.75 ); //   01 11   7
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  2.00 ); //   10 00   8
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  2.25 ); //   10 01   9
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  2.50 ); //   10 10  10
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  2.75 ); //   10 11  11
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  3.00 ); //   11 00  12
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  3.25 ); //   11 01  13
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  3.50 ); //   11 10  14
        ufixed_val = FixedLiteral( FIXED_ISUNSIGNED, 2, 2,  3.75 ); //   11 11  15
        delay;  // So you can see the last value when single stepping.
      }