Pigmeo was a compiler and framework for writing microcontroller firmware in C# and other .NET languages, developed by Adrián Bulnes (Urriellu) between 2007 and 2010. This is a frozen, read-only archive of the project’s website, pigmeo.org; nothing here is maintained. Source code: github.com/Urriellu/pigmeo · Original capture: Wayback Machine · urriellu.net

CCS PCM Output 002 - Call to sin()

From Pigmeo Development Wiki

C language

#include <16F716.h>
#include <math.h>
 
#byte	PORTB=0x06
 
void main() {
	PORTB=sin(30);
}

Assembly language

0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   4B7
0003:  NOP
.................... #include <16F716.h> 
.................... //////// Standard Header file for the PIC16F716 device //////////////// 
.................... #device PIC16F716 
.................... #list 
....................  
.................... #include <math.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2007 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////                                                                    //// 
.................... //// History:                                                           //// 
.................... ////  * 9/20/2001 :  Improvments are made to sin/cos code.              //// 
.................... ////                 The code now is small, much faster,                //// 
.................... ////                 and more accurate.                                 //// 
.................... ////  * 2/21/2007 :  Compiler handles & operator differently and does 
.................... ////                 not return generic (int8 *) so type cast is done   //// 
.................... ////                                                                    //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef MATH_H 
.................... #define MATH_H 
....................  
.................... #ifdef PI 
.................... #undef  PI 
.................... #endif 
.................... #define PI     3.141592654 
....................  
....................  
.................... #define SQRT2  1.41421356 
....................  
.................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279}; 
.................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718}; 
....................  
.................... ///////////////////////////// Round Functions ////////////////////////////// 
....................  
.................... float CEIL_FLOOR(float x, int n) 
.................... { 
....................    float y, res; 
....................    long l; 
....................    int1 s; 
....................  
....................    s = 0; 
....................    y = x; 
....................  
....................    if (x < 0) 
....................    { 
....................       s = 1; 
....................       y = -y; 
....................    } 
....................  
....................    if (y <= 32768.0) 
....................   res = (float)(long)y; 
....................  
....................  else if (y < 10000000.0) 
....................    { 
....................   l = (long)(y/32768.0); 
....................       y = 32768.0*(y/32768.0 - (float)l); 
....................   res = 32768.0*(float)l; 
....................   res += (float)(long)y; 
....................  } 
....................  
....................  else 
....................   res = y; 
....................  
....................  y = y - (float)(long)y; 
....................  
....................  if (s) 
....................   res = -res; 
....................  
....................  if (y != 0) 
....................  { 
....................   if (s == 1 && n == 0) 
....................    res -= 1.0; 
....................  
....................   if (s == 0 && n == 1) 
....................    res += 1.0; 
....................  } 
....................  if (x == 0) 
....................     res = 0; 
....................  
....................  return (res); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float floor(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : rounds down the number x. 
.................... // Date : N/A 
.................... // 
.................... float floor(float x) 
.................... { 
....................    return CEIL_FLOOR(x, 0); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float ceil(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : rounds up the number x. 
.................... // Date : N/A 
.................... // 
.................... float ceil(float x) 
.................... { 
....................    return CEIL_FLOOR(x, 1); 
.................... } 
....................  
....................  //////////////////////////////////////////////////////////////////////////// 
.................... //   float fabs(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : Computes the absolute value of floating point number x 
.................... // Returns : returns the absolute value of x 
.................... // Date : N/A 
.................... // 
.................... #define fabs abs 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float fmod(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : Computes the floating point remainder of x/y 
.................... // Returns : returns the value of x= i*y, for some integer i such that, if y 
.................... // is non zero, the result has the same isgn of x na dmagnitude less than the 
.................... // magnitude of y. If y is zero then a domain error occurs. 
.................... // Date : N/A 
.................... // 
....................  
.................... float fmod(float x,float y) 
.................... { 
....................    float i; 
....................    if (y!=0.0) 
....................    { 
....................       i=(x/y < 0.0)? ceil(x/y): floor(x/y); 
....................       return(x-(i*y)); 
....................    } 
....................    else 
....................    { 
....................    #ifdef _ERRNO 
....................    { 
....................       errno=EDOM; 
....................    } 
....................    #endif 
....................    } 
.................... } 
....................  
.................... //////////////////// Exponential and logarithmic functions //////////////////// 
....................  
.................... #define LN2 0.6931471806 
....................  
.................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093, 
....................                      0.0554965651,  0.240227138,  0.693147172}; 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float exp(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the value (e^x) 
.................... // Date : N/A 
.................... // 
.................... float exp(float x) 
.................... { 
....................    float y, res, r; 
....................    signed int n; 
....................    int1 s; 
....................    #ifdef _ERRNO 
....................    if(x > 88.722838) 
....................    { 
....................       errno=ERANGE; 
....................       return(0); 
....................    } 
....................    #endif 
....................    n = (signed long)(x/LN2); 
....................    s = 0; 
....................    y = x; 
....................  
....................    if (x < 0) 
....................    { 
....................       s = 1; 
....................       n = -n; 
....................       y = -y; 
....................    } 
....................  
....................    res = 0.0; 
....................    *((int8 *)(&res)) = n + 0x7F; 
....................  
....................    y = y/LN2 - (float)n; 
....................  
....................    r = pe[0]*y + pe[1]; 
....................    r = r*y + pe[2]; 
....................    r = r*y + pe[3]; 
....................    r = r*y + pe[4]; 
....................    r = r*y + pe[5]; 
....................  
....................    res = res*(1.0 + y*r); 
....................  
....................    if (s) 
....................       res = 1.0/res; 
....................    return(res); 
.................... } 
....................  
.................... /************************************************************/ 
....................  
.................... float const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189}; 
.................... float const ql[4] = {1.0000000,  -8.1354259, 16.780517, -9.9300943}; 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float log(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the the natural log of x 
.................... // Date : N/A 
.................... // 
.................... float log(float x) 
.................... { 
....................    float y, res, r, y2; 
....................  
....................    signed n; 
....................    #ifdef _ERRNO 
....................    if(x <0) 
....................    { 
....................       errno=EDOM; 
....................    } 
....................    if(x ==0) 
....................    { 
....................       errno=ERANGE; 
....................       return(0); 
....................    } 
....................    #endif 
....................    y = x; 
....................  
....................    if (y != 1.0) 
....................    { 
....................      *((int8 *)(&y)) = 0x7E;  
....................  
....................       y = (y - 1.0)/(y + 1.0); 
....................  
....................       y2=y*y; 
....................  
....................       res = pl[0]*y2 + pl[1]; 
....................       res = res*y2 + pl[2]; 
....................       res = res*y2 + pl[3]; 
....................  
....................       r = ql[0]*y2 + ql[1]; 
....................       r = r*y2 + ql[2]; 
....................       r = r*y2 + ql[3]; 
....................  
....................       res = y*res/r; 
....................  
....................       n = *((int8 *)(&x)) - 0x7E; 
....................  
....................       if (n<0) 
....................          r = -(float)-n; 
....................       else 
....................          r = (float)n; 
....................  
....................       res += r*LN2; 
....................    } 
....................  
....................    else 
....................       res = 0.0; 
....................  
....................    return(res); 
.................... } 
....................  
.................... #define LN10 2.30258509 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float log10(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the the log base 10 of x 
.................... // Date : N/A 
.................... // 
.................... float log10(float x) 
.................... { 
....................    float r; 
....................  
....................    r = log(x); 
....................    r = r/LN10; 
....................    return(r); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float modf(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description :breaks the argument value int integral and fractional parts, 
.................... // ach of which have the same sign as the argument.  It stores the integral part 
.................... // as a float in the object pointed to by the iptr 
.................... // Returns : returns the signed fractional part of value. 
.................... // Date : N/A 
.................... // 
....................  
.................... float modf(float value,float *iptr) 
.................... { 
....................    *iptr=(value < 0.0)? ceil(value): floor(value); 
....................    return(value - *iptr); 
.................... } 
....................  
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float pwr(float x,float y) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the value (x^y) 
.................... // Date : N/A 
.................... // 
.................... float pwr(float x,float y) 
.................... { 
....................    if(x>=0) 
....................      return(  exp(y*log(x)) ); 
....................    else 
....................      return(  -exp(y*log(-x)) ); 
.................... } 
....................  
....................  
.................... //////////////////// Power functions //////////////////// 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float pow(float x,float y) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the value (x^y) 
.................... // Date : N/A 
.................... // 
.................... float pow(float x,float y) 
.................... { 
....................    if(x>=0) 
....................      return(  exp(y*log(x)) ); 
....................    else 
....................      return(  -exp(y*log(-x)) ); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float sqrt(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the square root of x 
.................... // Date : N/A 
.................... // 
.................... float sqrt(float x) 
.................... { 
....................    float y, res; 
....................    BYTE *p; 
....................  
....................    #ifdef _ERRNO 
....................    if(x < 0) 
....................    { 
....................       errno=EDOM; 
....................    } 
....................    #endif 
....................  
....................    if( x<=0.0) 
....................       return(0.0); 
....................  
....................    y=x; 
....................    p=&y; 
....................    (*p)=(BYTE)((((int16)(*p)) + 127) >> 1); 
....................  
....................    do { 
....................       res=y; 
....................       y+=(x/y); 
....................       (*p)--; 
....................    } while(res != y); 
....................  
....................    return(res); 
.................... } 
....................  
....................  
....................  
.................... ////////////////////////////// Trig Functions ////////////////////////////// 
.................... #ifdef PI_DIV_BY_TWO 
.................... #undef PI_DIV_BY_TWO 
.................... #endif 
.................... #define PI_DIV_BY_TWO   1.570796326794896 
.................... #ifdef TWOBYPI 
.................... #undef TWOBYPI 
.................... #define TWOBYPI          0.6366197724 
.................... #endif 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float cos(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the cosine value of the angle x, which is in radian 
.................... // Date : 9/20/2001 
.................... // 
.................... float cos(float x) 
.................... { 
....................    float y, t, t2 = 1.0; 
*
02C2:  MOVLW  7F
02C3:  MOVWF  3E
02C4:  CLRF   3F
02C5:  CLRF   40
02C6:  CLRF   41
....................    int quad, i; 
....................    float frac; 
....................    float p[4] = { 
....................       -0.499999993585, 
....................        0.041666636258, 
....................       -0.0013888361399, 
....................        0.00002476016134 
....................    }; 
02C7:  MOVLW  7E
02C8:  MOVWF  48
02C9:  MOVLW  80
02CA:  MOVWF  49
02CB:  CLRF   4A
02CC:  CLRF   4B
02CD:  MOVLW  7A
02CE:  MOVWF  4C
02CF:  MOVLW  2A
02D0:  MOVWF  4D
02D1:  MOVLW  AA
02D2:  MOVWF  4E
02D3:  MOVLW  A3
02D4:  MOVWF  4F
02D5:  MOVLW  75
02D6:  MOVWF  50
02D7:  MOVLW  B6
02D8:  MOVWF  51
02D9:  MOVLW  09
02DA:  MOVWF  52
02DB:  MOVLW  9C
02DC:  MOVWF  53
02DD:  MOVLW  6F
02DE:  MOVWF  54
02DF:  MOVLW  4F
02E0:  MOVWF  55
02E1:  MOVLW  B4
02E2:  MOVWF  56
02E3:  MOVLW  0B
02E4:  MOVWF  57
....................  
....................    if (x < 0) x = -x;                  // absolute value of input 
02E5:  MOVF   35,W
02E6:  MOVWF  5B
02E7:  MOVF   34,W
02E8:  MOVWF  5A
02E9:  MOVF   33,W
02EA:  MOVWF  59
02EB:  MOVF   32,W
02EC:  MOVWF  58
02ED:  CLRF   5F
02EE:  CLRF   5E
02EF:  CLRF   5D
02F0:  CLRF   5C
*
032F:  BTFSS  03.0
0330:  GOTO   334
0331:  MOVF   33,W
0332:  XORLW  80
0333:  MOVWF  33
....................  
....................    quad = (int)(x / PI_DIV_BY_TWO);    // quadrant 
0334:  MOVF   35,W
0335:  MOVWF  5B
0336:  MOVF   34,W
0337:  MOVWF  5A
0338:  MOVF   33,W
0339:  MOVWF  59
033A:  MOVF   32,W
033B:  MOVWF  58
033C:  MOVLW  DB
033D:  MOVWF  5F
033E:  MOVLW  0F
033F:  MOVWF  5E
0340:  MOVLW  49
0341:  MOVWF  5D
0342:  MOVLW  7F
0343:  MOVWF  5C
0344:  CALL   142
0345:  MOVF   23,W
0346:  MOVWF  5B
0347:  MOVF   22,W
0348:  MOVWF  5A
0349:  MOVF   21,W
034A:  MOVWF  59
034B:  MOVF   20,W
034C:  MOVWF  58
034D:  CALL   20C
034E:  MOVF   21,W
034F:  MOVWF  42
....................    frac = (x / PI_DIV_BY_TWO) - quad;  // fractional part of input 
0350:  MOVF   35,W
0351:  MOVWF  5B
0352:  MOVF   34,W
0353:  MOVWF  5A
0354:  MOVF   33,W
0355:  MOVWF  59
0356:  MOVF   32,W
0357:  MOVWF  58
0358:  MOVLW  DB
0359:  MOVWF  5F
035A:  MOVLW  0F
035B:  MOVWF  5E
035C:  MOVLW  49
035D:  MOVWF  5D
035E:  MOVLW  7F
035F:  MOVWF  5C
0360:  CALL   142
0361:  MOVF   20,W
0362:  MOVWF  58
0363:  MOVF   21,W
0364:  MOVWF  59
0365:  MOVF   22,W
0366:  MOVWF  5A
0367:  MOVF   23,W
0368:  MOVWF  5B
0369:  CLRF   5D
036A:  MOVF   42,W
036B:  MOVWF  5C
*
0388:  BSF    03.1
0389:  MOVF   5B,W
038A:  MOVWF  60
038B:  MOVF   5A,W
038C:  MOVWF  5F
038D:  MOVF   59,W
038E:  MOVWF  5E
038F:  MOVF   58,W
0390:  MOVWF  5D
0391:  MOVF   23,W
0392:  MOVWF  64
0393:  MOVF   22,W
0394:  MOVWF  63
0395:  MOVF   21,W
0396:  MOVWF  62
0397:  MOVF   20,W
0398:  MOVWF  61
0399:  CALL   004
039A:  MOVF   23,W
039B:  MOVWF  47
039C:  MOVF   22,W
039D:  MOVWF  46
039E:  MOVF   21,W
039F:  MOVWF  45
03A0:  MOVF   20,W
03A1:  MOVWF  44
....................    quad = quad % 4;                    // quadrant (0 to 3) 
03A2:  MOVLW  03
03A3:  ANDWF  42,F
....................  
....................    if (quad == 0 || quad == 2) 
03A4:  MOVF   42,F
03A5:  BTFSC  03.2
03A6:  GOTO   3AB
03A7:  MOVF   42,W
03A8:  SUBLW  02
03A9:  BTFSS  03.2
03AA:  GOTO   3C5
....................       t = frac * PI_DIV_BY_TWO; 
03AB:  MOVF   47,W
03AC:  MOVWF  5F
03AD:  MOVF   46,W
03AE:  MOVWF  5E
03AF:  MOVF   45,W
03B0:  MOVWF  5D
03B1:  MOVF   44,W
03B2:  MOVWF  5C
03B3:  MOVLW  DB
03B4:  MOVWF  63
03B5:  MOVLW  0F
03B6:  MOVWF  62
03B7:  MOVLW  49
03B8:  MOVWF  61
03B9:  MOVLW  7F
03BA:  MOVWF  60
03BB:  CALL   22B
03BC:  MOVF   23,W
03BD:  MOVWF  3D
03BE:  MOVF   22,W
03BF:  MOVWF  3C
03C0:  MOVF   21,W
03C1:  MOVWF  3B
03C2:  MOVF   20,W
03C3:  MOVWF  3A
....................    else if (quad == 1) 
03C4:  GOTO   426
03C5:  DECFSZ 42,W
03C6:  GOTO   3F7
....................       t = (1-frac) * PI_DIV_BY_TWO; 
03C7:  BSF    03.1
03C8:  CLRF   60
03C9:  CLRF   5F
03CA:  CLRF   5E
03CB:  MOVLW  7F
03CC:  MOVWF  5D
03CD:  MOVF   47,W
03CE:  MOVWF  64
03CF:  MOVF   46,W
03D0:  MOVWF  63
03D1:  MOVF   45,W
03D2:  MOVWF  62
03D3:  MOVF   44,W
03D4:  MOVWF  61
03D5:  CALL   004
03D6:  MOVF   20,W
03D7:  MOVWF  58
03D8:  MOVF   21,W
03D9:  MOVWF  59
03DA:  MOVF   22,W
03DB:  MOVWF  5A
03DC:  MOVF   23,W
03DD:  MOVWF  5B
03DE:  MOVWF  5F
03DF:  MOVF   22,W
03E0:  MOVWF  5E
03E1:  MOVF   21,W
03E2:  MOVWF  5D
03E3:  MOVF   20,W
03E4:  MOVWF  5C
03E5:  MOVLW  DB
03E6:  MOVWF  63
03E7:  MOVLW  0F
03E8:  MOVWF  62
03E9:  MOVLW  49
03EA:  MOVWF  61
03EB:  MOVLW  7F
03EC:  MOVWF  60
03ED:  CALL   22B
03EE:  MOVF   23,W
03EF:  MOVWF  3D
03F0:  MOVF   22,W
03F1:  MOVWF  3C
03F2:  MOVF   21,W
03F3:  MOVWF  3B
03F4:  MOVF   20,W
03F5:  MOVWF  3A
....................    else // should be 3 
03F6:  GOTO   426
....................       t = (frac-1) * PI_DIV_BY_TWO; 
03F7:  BSF    03.1
03F8:  MOVF   47,W
03F9:  MOVWF  60
03FA:  MOVF   46,W
03FB:  MOVWF  5F
03FC:  MOVF   45,W
03FD:  MOVWF  5E
03FE:  MOVF   44,W
03FF:  MOVWF  5D
0400:  CLRF   64
0401:  CLRF   63
0402:  CLRF   62
0403:  MOVLW  7F
0404:  MOVWF  61
0405:  CALL   004
0406:  MOVF   20,W
0407:  MOVWF  58
0408:  MOVF   21,W
0409:  MOVWF  59
040A:  MOVF   22,W
040B:  MOVWF  5A
040C:  MOVF   23,W
040D:  MOVWF  5B
040E:  MOVWF  5F
040F:  MOVF   22,W
0410:  MOVWF  5E
0411:  MOVF   21,W
0412:  MOVWF  5D
0413:  MOVF   20,W
0414:  MOVWF  5C
0415:  MOVLW  DB
0416:  MOVWF  63
0417:  MOVLW  0F
0418:  MOVWF  62
0419:  MOVLW  49
041A:  MOVWF  61
041B:  MOVLW  7F
041C:  MOVWF  60
041D:  CALL   22B
041E:  MOVF   23,W
041F:  MOVWF  3D
0420:  MOVF   22,W
0421:  MOVWF  3C
0422:  MOVF   21,W
0423:  MOVWF  3B
0424:  MOVF   20,W
0425:  MOVWF  3A
....................  
....................    y = 0.999999999781; 
0426:  CLRF   39
0427:  CLRF   38
0428:  CLRF   37
0429:  MOVLW  7F
042A:  MOVWF  36
....................    t = t * t; 
042B:  MOVF   3D,W
042C:  MOVWF  5F
042D:  MOVF   3C,W
042E:  MOVWF  5E
042F:  MOVF   3B,W
0430:  MOVWF  5D
0431:  MOVF   3A,W
0432:  MOVWF  5C
0433:  MOVF   3D,W
0434:  MOVWF  63
0435:  MOVF   3C,W
0436:  MOVWF  62
0437:  MOVF   3B,W
0438:  MOVWF  61
0439:  MOVF   3A,W
043A:  MOVWF  60
043B:  CALL   22B
043C:  MOVF   23,W
043D:  MOVWF  3D
043E:  MOVF   22,W
043F:  MOVWF  3C
0440:  MOVF   21,W
0441:  MOVWF  3B
0442:  MOVF   20,W
0443:  MOVWF  3A
....................    for (i = 0; i <= 3; i++) 
0444:  CLRF   43
0445:  MOVF   43,W
0446:  SUBLW  03
0447:  BTFSS  03.0
0448:  GOTO   4A5
....................    { 
....................       t2 = t2 * t; 
0449:  MOVF   41,W
044A:  MOVWF  5F
044B:  MOVF   40,W
044C:  MOVWF  5E
044D:  MOVF   3F,W
044E:  MOVWF  5D
044F:  MOVF   3E,W
0450:  MOVWF  5C
0451:  MOVF   3D,W
0452:  MOVWF  63
0453:  MOVF   3C,W
0454:  MOVWF  62
0455:  MOVF   3B,W
0456:  MOVWF  61
0457:  MOVF   3A,W
0458:  MOVWF  60
0459:  CALL   22B
045A:  MOVF   23,W
045B:  MOVWF  41
045C:  MOVF   22,W
045D:  MOVWF  40
045E:  MOVF   21,W
045F:  MOVWF  3F
0460:  MOVF   20,W
0461:  MOVWF  3E
....................       y = y + p[i] * t2; 
0462:  RLF    43,W
0463:  MOVWF  20
0464:  RLF    20,F
0465:  MOVLW  FC
0466:  ANDWF  20,F
0467:  MOVF   20,W
0468:  ADDLW  48
0469:  MOVWF  04
046A:  MOVF   00,W
046B:  MOVWF  58
046C:  INCF   04,F
046D:  MOVF   00,W
046E:  MOVWF  59
046F:  INCF   04,F
0470:  MOVF   00,W
0471:  MOVWF  5A
0472:  INCF   04,F
0473:  MOVF   00,W
0474:  MOVWF  5B
0475:  MOVWF  5F
0476:  MOVF   5A,W
0477:  MOVWF  5E
0478:  MOVF   59,W
0479:  MOVWF  5D
047A:  MOVF   58,W
047B:  MOVWF  5C
047C:  MOVF   41,W
047D:  MOVWF  63
047E:  MOVF   40,W
047F:  MOVWF  62
0480:  MOVF   3F,W
0481:  MOVWF  61
0482:  MOVF   3E,W
0483:  MOVWF  60
0484:  CALL   22B
0485:  MOVF   04,W
0486:  MOVWF  5C
0487:  BCF    03.1
0488:  MOVF   39,W
0489:  MOVWF  60
048A:  MOVF   38,W
048B:  MOVWF  5F
048C:  MOVF   37,W
048D:  MOVWF  5E
048E:  MOVF   36,W
048F:  MOVWF  5D
0490:  MOVF   23,W
0491:  MOVWF  64
0492:  MOVF   22,W
0493:  MOVWF  63
0494:  MOVF   21,W
0495:  MOVWF  62
0496:  MOVF   20,W
0497:  MOVWF  61
0498:  CALL   004
0499:  MOVF   5C,W
049A:  MOVWF  04
049B:  MOVF   23,W
049C:  MOVWF  39
049D:  MOVF   22,W
049E:  MOVWF  38
049F:  MOVF   21,W
04A0:  MOVWF  37
04A1:  MOVF   20,W
04A2:  MOVWF  36
....................    } 
04A3:  INCF   43,F
04A4:  GOTO   445
....................  
....................    if (quad == 2 || quad == 1) 
04A5:  MOVF   42,W
04A6:  SUBLW  02
04A7:  BTFSC  03.2
04A8:  GOTO   4AB
04A9:  DECFSZ 42,W
04AA:  GOTO   4AE
....................       y = -y;  // correct sign 
04AB:  MOVF   37,W
04AC:  XORLW  80
04AD:  MOVWF  37
....................  
....................    return (y); 
04AE:  MOVF   36,W
04AF:  MOVWF  20
04B0:  MOVF   37,W
04B1:  MOVWF  21
04B2:  MOVF   38,W
04B3:  MOVWF  22
04B4:  MOVF   39,W
04B5:  MOVWF  23
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float sin(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the sine value of the angle x, which is in radian 
.................... // Date : 9/20/2001 
.................... // 
.................... float sin(float x) 
.................... { 
....................    return cos(x - PI_DIV_BY_TWO); 
*
02A0:  BSF    03.1
02A1:  MOVF   2D,W
02A2:  MOVWF  60
02A3:  MOVF   2C,W
02A4:  MOVWF  5F
02A5:  MOVF   2B,W
02A6:  MOVWF  5E
02A7:  MOVF   2A,W
02A8:  MOVWF  5D
02A9:  MOVLW  DB
02AA:  MOVWF  64
02AB:  MOVLW  0F
02AC:  MOVWF  63
02AD:  MOVLW  49
02AE:  MOVWF  62
02AF:  MOVLW  7F
02B0:  MOVWF  61
02B1:  CALL   004
02B2:  MOVF   20,W
02B3:  MOVWF  2E
02B4:  MOVF   21,W
02B5:  MOVWF  2F
02B6:  MOVF   22,W
02B7:  MOVWF  30
02B8:  MOVF   23,W
02B9:  MOVWF  31
02BA:  MOVF   31,W
02BB:  MOVWF  35
02BC:  MOVF   30,W
02BD:  MOVWF  34
02BE:  MOVF   2F,W
02BF:  MOVWF  33
02C0:  MOVF   2E,W
02C1:  MOVWF  32
.................... } 
*
04B6:  GOTO   4CE (RETURN)
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float tan(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the tangent value of the angle x, which is in radian 
.................... // Date : 9/20/2001 
.................... // 
.................... float tan(float x) 
.................... { 
....................    float c, s; 
....................  
....................    c = cos(x); 
....................    if (c == 0.0) 
....................       return (1.0e+36); 
....................  
....................    s = sin(x); 
....................    return(s/c); 
.................... } 
....................  
....................  
....................  
.................... float const pas[3] = {0.49559947, -4.6145309, 5.6036290}; 
.................... float const qas[3] = {1.0000000,  -5.5484666, 5.6036290}; 
....................  
.................... float ASIN_COS(float x, int n) 
.................... { 
....................    float y, res, r, y2; 
....................    int1 s; 
....................    #ifdef _ERRNO 
....................    if(x <-1 || x > 1) 
....................    { 
....................       errno=EDOM; 
....................    } 
....................    #endif 
....................    s = 0; 
....................    y = x; 
....................  
....................    if (x < 0) 
....................    { 
....................       s = 1; 
....................       y = -y; 
....................    } 
....................  
....................    if (y > 0.5) 
....................    { 
....................       y = sqrt((1.0 - y)/2.0); 
....................       n += 2; 
....................    } 
....................  
....................    y2=y*y; 
....................  
....................    res = pas[0]*y2 + pas[1]; 
....................    res = res*y2 + pas[2]; 
....................  
....................    r = qas[0]*y2 + qas[1]; 
....................    r = r*y2 + qas[2]; 
....................  
....................    res = y*res/r; 
....................  
....................    if (n & 2)     // |x| > 0.5 
....................       res = PI_DIV_BY_TWO - 2.0*res; 
....................    if (s) 
....................       res = -res; 
....................    if (n & 1)           // take arccos 
....................       res = PI_DIV_BY_TWO - res; 
....................  
....................    return(res); 
.................... } 
....................  
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float asin(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the arcsine value of the value x. 
.................... // Date : N/A 
.................... // 
.................... float asin(float x) 
.................... { 
....................    float r; 
....................  
....................    r = ASIN_COS(x, 0); 
....................    return(r); 
.................... } 
....................  
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float acos(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the arccosine value of the value x. 
.................... // Date : N/A 
.................... // 
.................... float acos(float x) 
.................... { 
....................    float r; 
....................  
....................    r = ASIN_COS(x, 1); 
....................    return(r); 
.................... } 
....................  
.................... float const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457}; 
.................... float const qat[4] = {1.0000000,  11.368190, 28.982246, 19.818457}; 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float atan(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : returns the arctangent value of the value x. 
.................... // Date : N/A 
.................... // 
.................... float atan(float x) 
.................... { 
....................    float y, res, r; 
....................    int1 s, flag; 
....................  
....................    s = 0; 
....................    flag = 0; 
....................    y = x; 
....................  
....................    if (x < 0) 
....................    { 
....................       s = 1; 
....................       y = -y; 
....................    } 
....................  
....................    if (y > 1.0) 
....................    { 
....................       y = 1.0/y; 
....................       flag = 1; 
....................    } 
....................  
....................    res = pat[0]*y*y + pat[1]; 
....................    res = res*y*y + pat[2]; 
....................    res = res*y*y + pat[3]; 
....................  
....................    r = qat[0]*y*y + qat[1]; 
....................    r = r*y*y + qat[2]; 
....................    r = r*y*y + qat[3]; 
....................  
....................    res = y*res/r; 
....................  
....................  
....................    if (flag)                              // for |x| > 1 
....................       res = PI_DIV_BY_TWO - res; 
....................    if (s) 
....................       res = -res; 
....................  
....................    return(res); 
.................... } 
....................  
.................... ///////////////////////////////////////////////////////////////////////////// 
.................... //   float atan2(float y, float x) 
.................... ///////////////////////////////////////////////////////////////////////////// 
.................... // Description :computes the principal value of arc tangent of y/x, using the 
.................... // signs of both the arguments to determine the quadrant of the return value 
.................... // Returns : returns the arc tangent of y/x. 
.................... // Date : N/A 
.................... // 
....................  
....................  
.................... float atan2(float y,float x) 
.................... { 
....................    float z; 
....................    int1 sign; 
....................    int quad; 
....................    sign=0; 
....................    quad=0; //quadrant 
....................    quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1)); 
....................    if(y<0.0) 
....................    { 
....................       sign=1; 
....................       y=-y; 
....................    } 
....................    if(x<0.0) 
....................    { 
....................       x=-x; 
....................    } 
....................    if (x==0.0) 
....................    { 
....................       if(y==0.0) 
....................       { 
....................       #ifdef _ERRNO 
....................       { 
....................          errno=EDOM; 
....................       } 
....................       #endif 
....................       } 
....................       else 
....................       { 
....................          if(sign) 
....................          { 
....................          return (-(PI_DIV_BY_TWO)); 
....................          } 
....................          else 
....................          { 
....................          return (PI_DIV_BY_TWO); 
....................          } 
....................       } 
....................    } 
....................    else 
....................    { 
....................       z=y/x; 
....................       switch(quad) 
....................       { 
....................          case 1: 
....................          { 
....................             return atan(z); 
....................             break; 
....................          } 
....................          case 2: 
....................          { 
.................... //            return (atan(z)+PI_DIV_BY_TWO);  //2L3122 
....................             return (PI-atan(z)); 
....................             break; 
....................          } 
....................          case 3: 
....................          { 
....................             return (atan(z)-PI); 
....................             break; 
....................          } 
....................          case 4: 
....................          { 
....................             return (-atan(z)); 
....................             break; 
....................          } 
....................       } 
....................    } 
.................... } 
....................  
.................... //////////////////// Hyperbolic functions //////////////////// 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float cosh(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : Computes the hyperbolic cosine value of x 
.................... // Returns : returns the hyperbolic cosine value of x 
.................... // Date : N/A 
.................... // 
....................  
.................... float cosh(float x) 
.................... { 
....................    return ((exp(x)+exp(-x))/2); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float sinh(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : Computes the hyperbolic sine value of x 
.................... // Returns : returns the hyperbolic sine value of x 
.................... // Date : N/A 
.................... // 
....................  
.................... float sinh(float x) 
.................... { 
....................  
....................    return ((exp(x) - exp(-x))/2); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float tanh(float x) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : Computes the hyperbolic tangent value of x 
.................... // Returns : returns the hyperbolic tangent value of x 
.................... // Date : N/A 
.................... // 
....................  
.................... float tanh(float x) 
.................... { 
....................    return(sinh(x)/cosh(x)); 
.................... } 
....................  
.................... //////////////////////////////////////////////////////////////////////////// 
.................... //   float frexp(float x, signed int *exp) 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... // Description : breaks a floating point number into a normalized fraction and an integral 
.................... // power of 2. It stores the integer in the signed int object pointed to by exp. 
.................... // Returns : returns the value x, such that x is a double with magnitude in the interval 
.................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero, 
.................... // both parts of the result are zero. 
.................... // Date : N/A 
.................... // 
....................  
....................  
....................  
.................... #define LOG2 .30102999566398119521 
.................... float frexp(float x, signed int *exp) 
.................... { 
....................    float res; 
....................    int1 sign = 0; 
....................    if(x == 0.0) 
....................    { 
....................       *exp=0; 
....................       return (0.0); 
....................    } 
....................    if(x < 0.0) 
....................    { 
....................      x=-x; 
....................      sign=1; 
....................    } 
....................    if (x > 1.0) 
....................    { 
....................       *exp=(ceil(log10(x)/LOG2)); 
....................       res=x/(pow(2, *exp)); 
....................       if (res == 1) 
....................       { 
....................          *exp=*exp+1; 
....................           res=.5; 
....................       } 
....................    } 
....................    else 
....................    { 
....................       if(x < 0.5) 
....................       { 
....................          *exp=-1; 
....................          res=x*2; 
....................       } 
....................       else 
....................       { 
....................          *exp=0; 
....................           res=x; 
....................       } 
....................    } 
....................    if(sign) 
....................    { 
....................       res=-res; 
....................    } 
....................    return res; 
.................... } 
....................  
.................... ////////////////////////////////////////////////////////////////////////////// 
.................... //   float ldexp(float x, signed int *exp) 
.................... ////////////////////////////////////////////////////////////////////////////// 
.................... // Description : multiplies a floating point number by an integral power of 2. 
.................... // Returns : returns the value of x times 2 raised to the power exp. 
.................... // Date : N/A 
.................... // 
....................  
.................... float ldexp(float value, signed int exp) 
.................... { 
....................    return (value * pow(2,exp)); 
.................... } 
.................... #endif 
....................  
....................  
.................... #byte	PORTB=0x06 
....................  
.................... void main() { 
04B7:  CLRF   04
04B8:  MOVLW  1F
04B9:  ANDWF  03,F
04BA:  BSF    03.5
04BB:  BSF    1F.0
04BC:  BSF    1F.1
04BD:  BSF    1F.2
.................... 	PORTB=sin(30); 
04BE:  MOVLW  83
04BF:  BCF    03.5
04C0:  MOVWF  26
04C1:  MOVLW  70
04C2:  MOVWF  27
04C3:  CLRF   28
04C4:  CLRF   29
04C5:  MOVF   29,W
04C6:  MOVWF  2D
04C7:  MOVF   28,W
04C8:  MOVWF  2C
04C9:  MOVF   27,W
04CA:  MOVWF  2B
04CB:  MOVF   26,W
04CC:  MOVWF  2A
04CD:  GOTO   2A0
04CE:  MOVF   23,W
04CF:  MOVWF  5B
04D0:  MOVF   22,W
04D1:  MOVWF  5A
04D2:  MOVF   21,W
04D3:  MOVWF  59
04D4:  MOVF   20,W
04D5:  MOVWF  58
04D6:  CALL   20C
04D7:  MOVF   21,W
04D8:  MOVWF  06
.................... } 
04D9:  SLEEP

Conclusions

  • CCS PCM does NOT optimize constantizable functions