打印

要是 -1

[复制链接]
楼主: xddzccn
手机看帖
扫描二维码
随时随地手机跟帖
41
IceAge| | 2008-6-20 20:30 | 只看该作者 回帖奖励 |倒序浏览

惭愧,当 hotpower 的老师,我不够格。

上面的表计算方法,用 CORDIC 会更简单。

exp(x) = exp( x0 +x1+x2+x3) = exp(x0)*exp(x1)*exp(x2)*exp(x3)

如果能让 exp(xk) = 2^N , 那么exp(x) 就简单多了,这就是 CORDIC的精髓。
把 x 分解:x = k0 + k1 + k2 + ... kn + m;
then  exp(x) = exp(k0)*exp(k1)* ... * exp(kn) *exp(m) = 2^N0 * 2^N1 * ... * exp(m). 这样就把 exp(x) 变成求 exp(m) ( 1< exp(m) < 2 , 0< m < ln2).
因为exp(m) >1,所以把 m 再分解到 1+1/2, 1+1/4, 1+1/8, ..., 1+1/2^K 序列,y*(1+1/2^k) = y + y>>k, 可以求得 exp(m).

x 查找的两个序列:
[128*ln(2), 64*ln(2), 32*ln(2), ..., 2*ln(2), ln(2)], 左移序列
[ln(1+1/2), ln(1+1/4), ..., ln(1+1/2^K)], y = y + y>>K 序列 
 


 

 

使用特权

评论回复
42
IceAge| | 2008-6-20 21:19 | 只看该作者

做了一个程序验证了一下

#include "stdafx.h"
#include "math.h"

#define LN2 0.69314718055994530941723212145818f

float C1[] = 
{
    128*LN2, 64*LN2, 32*LN2, 16*LN2, 8*LN2, 4*LN2, 2*LN2, LN2
};

float C2[] = 
{
    0.405465108f, 0.223143551f, 0.117783036f, 0.060624622f,
    0.030771659f, 0.015504187f, 0.00778214f, 0.00389864f,
    0.00195122f, 0.000976086f, 0.000488162f, 0.000244111f
};


float Exp(float x)
{
    float y = 1.0;
    float t = x;
    int i;
    for (i=0; i<8; i++) {
        if (t > C1) {
            t -= C1;
            y *= 1L <<(1<<(7-i));
        }
    }
    for (i=0; i<12; i++) {
        if (t > C2) {
            t -= C2;
            y += y / (1<<(i+1));
        }
    }
    return y;    
}

int _tmain(int argc, _TCHAR* argv[])
{
    float y1 = Exp(10.0);
    float y2 = (float) exp(10.0);

    printf("%4.5f   %4.5f", y1, y2);
    return 0;
}

结果:22026.41406   22026.46484

注意:y *= 1L <<(1<<(7-i));y / (1<<(i+1)),可以通过移位实现 

使用特权

评论回复
43
xddzccn|  楼主 | 2008-6-22 20:48 | 只看该作者

IceAge 单向逼近

IceAge 单向逼近

使用特权

评论回复
44
xddzccn|  楼主 | 2008-6-22 20:52 | 只看该作者

rs

有几个问题 请教 IceAge 
rs

使用特权

评论回复
45
xddzccn|  楼主 | 2008-6-22 21:12 | 只看该作者

一篇cordic的论文

大家都来看看,说不定什么时候能用到!

使用特权

评论回复
46
xddzccn|  楼主 | 2008-6-22 21:25 | 只看该作者

cordic

cordic

使用特权

评论回复
47
gyt| | 2008-6-23 10:57 | 只看该作者

挺好

使用特权

评论回复
48
IceAge| | 2008-6-23 21:05 | 只看该作者

关于单向逼近

exp 与 cos,sin 不同之处是:
exp(-x) = 1/exp(x) (x>>N, 会损失精度) 
cos(-x) = cos(x), sin(-x) = -sin(x)

cos,sin 双向逼近,内部有x+(y>>N), x-(y>>N) 操作。
而exp 如果采用双向逼近,则全部为移位操作,很难得到一个精确值。所以要利用  1+1/2^N, 1-1/2^N, 不至于让单纯的右移损失精度。

使用特权

评论回复
49
小小草| | 2008-6-23 22:55 | 只看该作者

纯粹帮忙

呵呵,其实我什么都看不懂,纯粹帮忙而已

使用特权

评论回复
50
armfpga| | 2008-6-26 08:41 | 只看该作者

不错 ,虽然看的晕晕乎乎的

不错 ,虽然看的晕晕乎乎的 
不过好像坛子里面数学学得好的不多啊 .

使用特权

评论回复
51
yarpy1014| | 2008-6-26 20:13 | 只看该作者

头大了

都有点印象,但都记得不清楚了

使用特权

评论回复
52
ldy216| | 2008-7-4 15:47 | 只看该作者

函数

QQ:184324486
  超级大师


;-------------------------------------------------------------------------------
;FUNCTION:      CAL SIN(X) OR   COS(X)
;               TEMPFLAG4=0 FOR SIN(X),TEMPFLAG4=1 FOR COS(X)
;               X=(BINARY FLOAT)CAL_TEMP(3_0)   RETURN: FLOAT CAL_TEMP(3_0)
LDY_SINCOS:
                MOV     A,R0
                PUSH    ACC
                MOV     A,R1
                PUSH    ACC
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7
                PUSH    CAL_TEMP8
                PUSH    CAL_TEMP9
                PUSH    CAL_TEMPA
                PUSH    CAL_TEMPB
                PUSH    CAL_TEMPC
                PUSH    CAL_TEMPD
                PUSH    CAL_TEMPE
                PUSH    CAL_TEMPF
                PUSH    CAL_TEMPG
                PUSH    CAL_TEMPH
                PUSH    CAL_TEMPI
                PUSH    CAL_TEMPJ

                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                MOV     CAL_TEMP7,#0EAH
                MOV     CAL_TEMP6,#01100100B
                MOV     CAL_TEMP5,#10000111B
                MOV     CAL_TEMP4,#11101101B     ;CAL_TEMP7_4=PAI/2

                LCALL   FLOAT_DIV
                LCALL   FLOAT_INT
                MOV     A,CAL_TEMP0
                CPL     A
                ADD     A,#001H
                ANL     A,#003H
                MOV     R0,A
                LCALL   FLOATTODOUBLE
                MOV     CAL_TEMPF,#0FFH           ;DOUBLE  PAI/2
                MOV     CAL_TEMPE,#0D2H
                MOV     CAL_TEMPD,#01100100B
                MOV     CAL_TEMPC,#10000111B
                MOV     CAL_TEMPB,#11101101B
                MOV     CAL_TEMPA,#01010001B
                MOV     CAL_TEMP9,#00010000B
                MOV     CAL_TEMP8,#10110100B
                LCALL   DOUBLE_MUL
                LCALL   BYTE8_SWAP
                MOV     CAL_TEMP0,CAL_TEMPG
                MOV     CAL_TEMP1,CAL_TEMPH
                MOV     CAL_TEMP2,CAL_TEMPI
                MOV     CAL_TEMP3,CAL_TEMPJ
                LCALL   FLOATTODOUBLE
                CALL    DOUBLE_SUB
                CALL    DOUBLETOFLOAT

                MOV     A,R0
                JNB     FLAG_TEMP4,SINCOS_TESTSINCOS
                CPL     ACC.0
SINCOS_TESTSINCOS:
                MOV     R1,A
                ;奇变余偶不变
                JNB     ACC.0,SINCOS_SIN
SINCOS_COS:
                ;TURN COS TO SIN
                ;CAL_TEMP7_4=PAI/2
                MOV     CAL_TEMP7,#0EAH
                MOV     CAL_TEMP6,#01100100B
                MOV     CAL_TEMP5,#10000111B
                MOV     CAL_TEMP4,#11101101B
                LCALL   BYTE4_SWAP
                LCALL   FLOAT_SUB
SINCOS_SIN:
                ;符号看原函数 K/4+1  象限
                MOV     A,R1
                JNB     ACC.0,SINCOS_SIN_SETSIGN
                INC     R0
SINCOS_SIN_SETSIGN:

                MOV     A,R0
                MOV     C,ACC.1
                MOV     FLAG_TEMP3,C       ;SIGN OF SIN(X)
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                ;X>PAI/4 ?  CAL COS(PAI/2-X)
                ;CAL_TEMP7_4=PAI/4
                MOV     CAL_TEMP7,#0E9H
                MOV     CAL_TEMP6,#01100100B
                MOV     CAL_TEMP5,#10000111B
                MOV     CAL_TEMP4,#11101101B
                LCALL   FLOAT_SUB
                MOV     A,CAL_TEMP2
                JB      ACC.7,SINCOS_INITSUM_1
                ;CAL_TEMP3_0=PAI/2
                MOV     CAL_TEMP3,#0EAH
                MOV     CAL_TEMP2,#01100100B
                MOV     CAL_TEMP1,#10000111B
                MOV     CAL_TEMP0,#11101101B

                MOV     CAL_TEMP7,CAL_TEMPB
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP4,CAL_TEMP8
                LCALL   FLOAT_SUB

                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3
SINCOS_INITSUM_0:
                ;CAL_TEMP(C-F)=ITEM,  CAL_TEMP(G-J)=SUM
                MOV     CAL_TEMPC,#001H
                MOV     CAL_TEMPG,#001H
                MOV     CAL_TEMPD,#000H
                MOV     CAL_TEMPH,#000H
                MOV     CAL_TEMPE,#000H
                MOV     CAL_TEMPI,#000H
                MOV     CAL_TEMPF,#000H
                MOV     CAL_TEMPJ,#000H
                MOV     R0,#000H
                LJMP    SINCOS_MUL_INIT
SINCOS_INITSUM_1:
                ;CAL_TEMP(C-F)=ITEM

                MOV     CAL_TEMPC,CAL_TEMP8
                MOV     CAL_TEMPG,CAL_TEMP8
                MOV     CAL_TEMPD,CAL_TEMP9
                MOV     CAL_TEMPH,CAL_TEMP9

                MOV     CAL_TEMPE,CAL_TEMPA
                MOV     CAL_TEMPI,CAL_TEMPA
                MOV     CAL_TEMPF,CAL_TEMPB
                MOV     CAL_TEMPJ,CAL_TEMPB
                MOV     R0,#001H
SINCOS_MUL_INIT:
                ;CAL_TEMP(B-8)=X*X
                MOV     CAL_TEMP0,CAL_TEMP8
                MOV     CAL_TEMP4,CAL_TEMP8
                MOV     CAL_TEMP1,CAL_TEMP9
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP2,CAL_TEMPA
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP3,CAL_TEMPB
                MOV     CAL_TEMP7,CAL_TEMPB
                LCALL    FLOAT_MUL
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                MOV     R1,#004H       ;5 ITEMS  END ITEM=-X^9/9!
                CLR     ITEMFLAG       ;ITEM SIGN
LOOP_SINCOS_MUL:
                INC     R0
                MOV     A,R0
                INC     R0
                MOV     B,R0
                MUL     AB
                MOV     CAL_TEMP4,A  ;=N*(N+1)
                MOV     CAL_TEMP5,#000H
                MOV     CAL_TEMP6,#000H
                MOV     CAL_TEMP7,#000H

                MOV     CAL_TEMP0,CAL_TEMPC
                MOV     CAL_TEMP1,CAL_TEMPD
                MOV     CAL_TEMP2,CAL_TEMPE
                MOV     CAL_TEMP3,CAL_TEMPF
                LCALL   FLOAT_DIV
                MOV     CAL_TEMP4,CAL_TEMP8
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP7,CAL_TEMPB
                LCALL   FLOAT_MUL

                MOV     CAL_TEMPC,CAL_TEMP0
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPF,CAL_TEMP3
                JNB     ITEMFLAG,SINCOS_ITEM_N
SINCOS_ITEM_P:
                CLR     ITEMFLAG
                LJMP    SINCOS_SUMITEM
SINCOS_ITEM_N:
                SETB    ITEMFLAG
                LCALL   BYTE3_NEGATIVE

SINCOS_SUMITEM:
                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                DJNZ    R1,LOOP_SINCOS_MUL
                JNB     FLAG_TEMP3,EXIT_LDYSINCOS
                LCALL    BYTE3_NEGATIVE
EXIT_LDYSINCOS:
                POP     CAL_TEMPJ
                POP     CAL_TEMPI
                POP     CAL_TEMPH
                POP     CAL_TEMPG
                POP     CAL_TEMPF
                POP     CAL_TEMPE
                POP     CAL_TEMPD
                POP     CAL_TEMPC
                POP     CAL_TEMPB
                POP     CAL_TEMPA
                POP     CAL_TEMP9
                POP     CAL_TEMP8
                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4

                POP     ACC
                MOV     R1,A
                POP     ACC
                MOV     R0,A

                RET
;-------------------------------------------------------------------------------
;FUNCTION:   CAL  SIN(X)  X=CAL_TEMP(3_0),  X=BINARY FLOAT
LDY_SIN:
                PUSH    CAL_STATE1
                CLR     TEMPFLAG4
                LCALL   LDY_SINCOS
                POP     CAL_STATE1
                RET
;-------------------------------------------------------------------------------
;FUNCTION:   CAL  COS(X)  X=CAL_TEMP(3_0),  X=BINARY FLOAT
LDY_COS:
                PUSH    CAL_STATE1
                SETB    TEMPFLAG4
                LCALL   LDY_SINCOS
                POP     CAL_STATE1
                RET

使用特权

评论回复
53
ldy216| | 2008-7-4 15:49 | 只看该作者

函数-2

QQ:184324486
超级大师

;-------------------------------------------------------------------------------
LDY_ARCSINCOS:
                PUSH    ACC
                PUSH    PSW
                MOV     A,R0
                PUSH    ACC
                MOV     A,R1
                PUSH    ACC
                MOV     A,R2
                PUSH    ACC

                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7
                PUSH    CAL_TEMP8
                PUSH    CAL_TEMP9
                PUSH    CAL_TEMPA
                PUSH    CAL_TEMPB
                PUSH    CAL_TEMPC
                PUSH    CAL_TEMPD
                PUSH    CAL_TEMPE
                PUSH    CAL_TEMPF
                PUSH    CAL_TEMPG
                PUSH    CAL_TEMPH
                PUSH    CAL_TEMPI
                PUSH    CAL_TEMPJ

                MOV     R2,#000H    ;Y1=Y*2^R2
                CLR     FLAG_TEMP3
                MOV     A,CAL_TEMP2
                JNB     ACC.7,ARCSINCOS_INIT
                SETB    FLAG_TEMP3
                LCALL   BYTE3_NEGATIVE   ;ABS(X)
ARCSINCOS_INIT:
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                MOV     CAL_TEMP7,#0EAH        ;CAL_TEMP(7_4)=1
                MOV     CAL_TEMP6,#01000000B
                MOV     CAL_TEMP5,#00000000B
                MOV     CAL_TEMP4,#00000000B
                LCALL   FLOAT_SUB
                MOV     A,CAL_TEMP2
                JB      ACC.7,EXIT_ARCSINCOS_INIT

                ;X>=1 ,Y=PAI/2,  CAL_TEMP3_0=PAI/2
                MOV     CAL_TEMP3,#0EAH
                MOV     CAL_TEMP2,#01100100B
                MOV     CAL_TEMP1,#10000111B
                MOV     CAL_TEMP0,#11101101B
                LJMP    EXIT_ARCSINCOS_MUL
EXIT_ARCSINCOS_INIT:
                MOV     CAL_TEMP0,CAL_TEMP8
                MOV     CAL_TEMP1,CAL_TEMP9
                MOV     CAL_TEMP2,CAL_TEMPA
                MOV     CAL_TEMP3,CAL_TEMPB
LOOP_ARCSINCOS_HALFANGLE:
                ;SIN(Y/2)=SQR((1-SQR(1-SIN(Y)*SIN(Y)))/2)
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                ;CAL_TEMP(7_4)=0.1
                MOV     CAL_TEMP7,#0E6H
                MOV     CAL_TEMP6,#01100110B
                MOV     CAL_TEMP5,#01100110B
                MOV     CAL_TEMP4,#01100110B
                LCALL   FLOAT_SUB
                MOV     A,CAL_TEMP2
                JNB     ACC.7,ARCSINCOS_GETHALFANGLE
                LJMP    ARCSINCOS_MUL_INIT    ;0<=X<0.1 ?
ARCSINCOS_GETHALFANGLE:
                INC     R2
                MOV     CAL_TEMP0,CAL_TEMPG
                MOV     CAL_TEMP1,CAL_TEMPH
                MOV     CAL_TEMP2,CAL_TEMPI
                MOV     CAL_TEMP3,CAL_TEMPJ
                LCALL   FLOATTODOUBLE

                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3
                MOV     CAL_TEMPC,CAL_TEMP4
                MOV     CAL_TEMPD,CAL_TEMP5
                MOV     CAL_TEMPE,CAL_TEMP6
                MOV     CAL_TEMPF,CAL_TEMP7
                LCALL    DOUBLE_MUL
                LCALL    BYTE8_SWAP

                ;CAL_TEMP(7_0)=1
                MOV     CAL_TEMP7,#0FFH
                MOV     CAL_TEMP6,#0D2H
                MOV     CAL_TEMP5,#01000000B
                MOV     CAL_TEMP4,#000H
                MOV     CAL_TEMP3,#000H
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP0,#000H
                LCALL   DOUBLE_SUB
                LCALL   DOUBLE_SQUAREROOT
                LCALL   BYTE8_SWAP

                ;CAL_TEMP(7_0)=1
                MOV     CAL_TEMP7,#0FFH
                MOV     CAL_TEMP6,#0D2H
                MOV     CAL_TEMP5,#01000000B
                MOV     CAL_TEMP4,#000H
                MOV     CAL_TEMP3,#000H
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP0,#000H
                LCALL   DOUBLE_SUB

                CLR     C
                MOV     A,CAL_TEMP6
                SUBB    A,#001H
                MOV     CAL_TEMP6,A
                MOV     A,CAL_TEMP7
                SUBB    A,#000H
                MOV     CAL_TEMP7,A

                LCALL   DOUBLE_SQUAREROOT
                LCALL   DOUBLETOFLOAT
                LJMP    LOOP_ARCSINCOS_HALFANGLE

ARCSINCOS_MUL_INIT:
                ;CAL_TEMP(C-F)=ITEM
                ;CAL_TEMP(G-J)=SUM
                ;CAL_TEMP(B-8)=X*X
                MOV     CAL_TEMP0,CAL_TEMPG
                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP8,CAL_TEMPG
                MOV     CAL_TEMPC,CAL_TEMPG

                MOV     CAL_TEMP1,CAL_TEMPH
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP9,CAL_TEMPH
                MOV     CAL_TEMPD,CAL_TEMPH

                MOV     CAL_TEMP2,CAL_TEMPI
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMPA,CAL_TEMPI
                MOV     CAL_TEMPE,CAL_TEMPI

                MOV     CAL_TEMP3,CAL_TEMPJ
                MOV     CAL_TEMP7,CAL_TEMPJ
                MOV     CAL_TEMPB,CAL_TEMPJ
                MOV     CAL_TEMPF,CAL_TEMPJ

                CALL    FLOAT_MUL
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                ;5 ITEMS  END ITEM=3^2*5^2*7^2/9!*X^9
                MOV     R1,#004H
                MOV     R0,#001H
LOOP_ARCSINCOS_MUL:
                MOV     A,R0
                MOV     B,R0
                MUL     AB
                MOV     CAL_TEMP4,A
                MOV     CAL_TEMP5,#000H
                MOV     CAL_TEMP6,#000H
                MOV     CAL_TEMP7,#000H

                MOV     CAL_TEMP0,CAL_TEMPC
                MOV     CAL_TEMP1,CAL_TEMPD
                MOV     CAL_TEMP2,CAL_TEMPE
                MOV     CAL_TEMP3,CAL_TEMPF

                LCALL   FLOAT_MUL
                LCALL   BYTE4_SWAP

                INC     R0
                MOV     A,R0
                INC     R0
                MOV     B,R0
                MUL     AB
                MOV     CAL_TEMP0,A
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP3,#000H
                LCALL   BYTE4_SWAP
                LCALL   FLOAT_DIV

                MOV     CAL_TEMP4,CAL_TEMP8
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP7,CAL_TEMPB
                LCALL   FLOAT_MUL

                MOV     CAL_TEMPC,CAL_TEMP0
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPF,CAL_TEMP3

                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                DJNZ    R1,LOOP_ARCSINCOS_MUL
EXIT_ARCSINCOS_MUL:
                MOV     A,R2
                ADD     A,CAL_TEMP3
                MOV     CAL_TEMP3,A
                JNB     FLAG_TEMP3,ARCSINCOS_GETSINCOS
                LCALL   BYTE3_NEGATIVE
ARCSINCOS_GETSINCOS:
                JNB     FLAG_TEMP4,EXIT_LDY_ARCSINCOS
                ;ARCCOS(X)=PAI/2-ARCSIN(X)
                ;CAL_TEMP3_0=PAI/2
                LCALL   BYTE4_SWAP
                MOV     CAL_TEMP3,#0EAH
                MOV     CAL_TEMP2,#01100100B
                MOV     CAL_TEMP1,#10000111B
                MOV     CAL_TEMP0,#11101101B
                LCALL   FLOAT_SUB

EXIT_LDY_ARCSINCOS:
                POP     CAL_TEMPJ
                POP     CAL_TEMPI
                POP     CAL_TEMPH
                POP     CAL_TEMPG
                POP     CAL_TEMPF
                POP     CAL_TEMPE
                POP     CAL_TEMPD
                POP     CAL_TEMPC
                POP     CAL_TEMPB
                POP     CAL_TEMPA
                POP     CAL_TEMP9
                POP     CAL_TEMP8
                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                POP     ACC
                MOV     R2,A
                POP     ACC
                MOV     R1,A
                POP     ACC
                MOV     R0,A
                POP     PSW
                POP     ACC
                RET
;-------------------------------------------------------------------------------
;FUNCTION:   CAL  ARCSIN(X)  X=CAL_TEMP(3_0)=[-1,1],X=BINARY FLOAT
LDY_ARCSIN:
                PUSH    CAL_STATE1
                CLR     FLAG_TEMP4
                LCALL   LDY_ARCSINCOS
                POP     CAL_STATE1
                RET
;-------------------------------------------------------------------------------
;FUNCTION:   CAL  ARCCOS(X)  X=CAL_TEMP(3_0)=[-1,1]
LDY_ARCCOS:
                PUSH    CAL_STATE1
                SETB    TEMPFLAG4
                LCALL   LDY_ARCSINCOS
                POP     CAL_STATE1

                RET

使用特权

评论回复
54
ldy216| | 2008-7-4 15:51 | 只看该作者

函数-3

QQ:184324486
超级大师LDY
;-------------------------------------------------------------------------------
LDY_TAN:
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7

                MOV     CAL_TEMP4,CAL_TEMP0
                MOV     CAL_TEMP5,CAL_TEMP1
                MOV     CAL_TEMP6,CAL_TEMP2
                MOV     CAL_TEMP7,CAL_TEMP3
                LCALL   LDY_COS
                LCALL   BYTE4_SWAP
                LCALL   LDY_SIN
                LCALL   FLOAT_DIV

                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                RET
;-------------------------------------------------------------------------------
LDY_CTG:
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7

                MOV     CAL_TEMP4,CAL_TEMP0
                MOV     CAL_TEMP5,CAL_TEMP1
                MOV     CAL_TEMP6,CAL_TEMP2
                MOV     CAL_TEMP7,CAL_TEMP3
                LCALL   LDY_SIN
                LCALL   BYTE4_SWAP
                LCALL   LDY_COS
                LCALL   FLOAT_DIV

                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                RET

;-------------------------------------------------------------------------------
LDY_ARCTANCTG:
                MOV     A,R0
                PUSH    ACC
                MOV     A,R1
                PUSH    ACC
                MOV     A,R2
                PUSH    ACC
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7
                PUSH    CAL_TEMP8
                PUSH    CAL_TEMP9
                PUSH    CAL_TEMPA
                PUSH    CAL_TEMPB
                PUSH    CAL_TEMPC
                PUSH    CAL_TEMPD
                PUSH    CAL_TEMPE
                PUSH    CAL_TEMPF
                PUSH    CAL_TEMPG
                PUSH    CAL_TEMPH
                PUSH    CAL_TEMPI
                PUSH    CAL_TEMPJ

                MOV     R2,#000H    ;Y1=Y*2^R2
                CLR     FLAG_TEMP3
                MOV     A,CAL_TEMP2
                JNB     ACC.7,LOOP_ARCTANCTG_HALFANGLE
                SETB    TEMPFLAG3
                LCALL    BYTE3_NEGATIVE   ;ABS(X)
LOOP_ARCTANCTG_HALFANGLE:
                ;TAN(Y/2)=(-1+SQR(1+TAN(Y)*TAN(Y)))/TAN(Y)
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                ;CAL_TEMP(7_4)=0.1
                MOV     CAL_TEMP7,#0E6H
                MOV     CAL_TEMP6,#01100110B
                MOV     CAL_TEMP5,#01100110B
                MOV     CAL_TEMP4,#01100110B
                LCALL   FLOAT_SUB
                MOV     A,CAL_TEMP2
                JNB     ACC.7,ARCTANCTG_GETHALFANGLE   ; 0<=X<0.1 ?
                LJMP    ARCTANCTG_MUL_INIT
ARCTANCTG_GETHALFANGLE:
                INC     R2
                MOV     CAL_TEMP0,CAL_TEMPG
                MOV     CAL_TEMP1,CAL_TEMPH
                MOV     CAL_TEMP2,CAL_TEMPI
                MOV     CAL_TEMP3,CAL_TEMPJ
                LCALL   FLOATTODOUBLE

                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3
                MOV     CAL_TEMPC,CAL_TEMP4
                MOV     CAL_TEMPD,CAL_TEMP5
                MOV     CAL_TEMPE,CAL_TEMP6
                MOV     CAL_TEMPF,CAL_TEMP7
                LCALL   DOUBLE_MUL

                MOV     CAL_TEMPF,#0FFH  ;CAL_TEMP(F_8)=1
                MOV     CAL_TEMPE,#0D2H
                MOV     CAL_TEMPD,#01000000B
                MOV     CAL_TEMPC,#000H
                MOV     CAL_TEMPB,#000H
                MOV     CAL_TEMPA,#000H
                MOV     CAL_TEMP9,#000H
                MOV     CAL_TEMP8,#000H
                LCALL    DOUBLE_ADD
                LCALL    DOUBLE_SQUAREROOT
                MOV     CAL_TEMPF,#0FFH  ;CAL_TEMP(F_8)=1
                MOV     CAL_TEMPE,#0D2H
                MOV     CAL_TEMPD,#01000000B
                MOV     CAL_TEMPC,#000H
                MOV     CAL_TEMPB,#000H
                MOV     CAL_TEMPA,#000H
                MOV     CAL_TEMP9,#000H
                MOV     CAL_TEMP8,#000H
                CALL    DOUBLE_SUB

                MOV     CAL_TEMPE,CAL_TEMPJ
                MOV     CAL_TEMPF,#000H
                MOV     A,CAL_TEMPJ
                JNB     ACC.7,ARCTANCTG_1
                MOV     CAL_TEMPF,#0FFH
ARCTANCTG_1:
                MOV     CAL_TEMP8,CAL_TEMPG
                MOV     CAL_TEMP9,CAL_TEMPH
                MOV     CAL_TEMPA,CAL_TEMPI

                MOV     CAL_TEMPB,#000H
                MOV     A,CAL_TEMPI
                JNB     ACC.7,ARCTANCTG_2
                MOV     CAL_TEMPB,#0FFH
ARCTANCTG_2:
                MOV     CAL_TEMPC,CAL_TEMPB
                MOV     CAL_TEMPD,CAL_TEMPB
                LCALL   DOUBLE_DIV
                LCALL   DOUBLETOFLOAT
                LJMP    LOOP_ARCTANCTG_HALFANGLE

ARCTANCTG_MUL_INIT:
                ;CAL_TEMP(C-F)=ITEM
                ;CAL_TEMP(G-J)=SUM
                ;CAL_TEMP(B-8)=X*X
                MOV     CAL_TEMP0,CAL_TEMPG
                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP8,CAL_TEMPG
                MOV     CAL_TEMPC,CAL_TEMPG

                MOV     CAL_TEMP1,CAL_TEMPH
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP9,CAL_TEMPH
                MOV     CAL_TEMPD,CAL_TEMPH

                MOV     CAL_TEMP2,CAL_TEMPI
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMPE,CAL_TEMPI
                MOV     CAL_TEMPA,CAL_TEMPI

                MOV     CAL_TEMP3,CAL_TEMPJ
                MOV     CAL_TEMP7,CAL_TEMPJ
                MOV     CAL_TEMPB,CAL_TEMPJ
                MOV     CAL_TEMPF,CAL_TEMPJ

                LCALL   FLOAT_MUL
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                MOV     R1,#004H      ;5 ITEMS  END ITEM=+1/9*X^9
                MOV     R0,#001H
                CLR     ITEMFLAG
LOOP_ARCTANCTG_MUL:

                MOV     CAL_TEMP0,CAL_TEMPC
                MOV     CAL_TEMP1,CAL_TEMPD
                MOV     CAL_TEMP2,CAL_TEMPE
                MOV     CAL_TEMP3,CAL_TEMPF

                MOV     CAL_TEMP4,CAL_TEMP8
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP7,CAL_TEMPB
                LCALL   FLOAT_MUL
                MOV     CAL_TEMPC,CAL_TEMP0
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPF,CAL_TEMP3

                INC     R0
                INC     R0
                MOV     A,R0
                MOV     CAL_TEMP4,A
                MOV     CAL_TEMP5,#000H
                MOV     CAL_TEMP6,#000H
                MOV     CAL_TEMP7,#000H
                LCALL   FLOAT_DIV

                JNB     ITEMFLAG,ARCTANCTG_ITEM_N
ARCTANCTG_ITEM_P:
                CLR     ITEMFLAG
                LJMP    ARCTANCTG_SUMITEM
ARCTANCTG_ITEM_N:
                SETB    ITEMFLAG
                LCALL    BYTE3_NEGATIVE

ARCTANCTG_SUMITEM:
                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                DJNZ    R1,LOOP_ARCTANCTG_MUL

EXIT_ARCTANCTG_MUL:
                MOV     A,CAL_TEMP3
                ADD     A,R2
                MOV     CAL_TEMP3,A
                JNB     FLAG_TEMP4,TANCTG_TESTSIGN

                ;ARCCTG(X)=PAI/2-ARCTAN(X)  X>0
                ;CAL_TEMP3_0=PAI/2
                LCALL   BYTE4_SWAP
                MOV     CAL_TEMP3,#0EAH     ;PAI/2
                MOV     CAL_TEMP2,#01100100B
                MOV     CAL_TEMP1,#10000111B
                MOV     CAL_TEMP0,#11101101B
                LCALL   FLOAT_SUB
TANCTG_TESTSIGN:
                JNB     FLAG_TEMP3,EXIT_LDY_ARCTANCTG
                LCALL    BYTE3_NEGATIVE

EXIT_LDY_ARCTANCTG:
                POP     CAL_TEMPJ
                POP     CAL_TEMPI
                POP     CAL_TEMPH
                POP     CAL_TEMPG
                POP     CAL_TEMPF
                POP     CAL_TEMPE
                POP     CAL_TEMPD
                POP     CAL_TEMPC
                POP     CAL_TEMPB
                POP     CAL_TEMPA
                POP     CAL_TEMP9
                POP     CAL_TEMP8
                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                POP     ACC
                MOV     R2,A
                POP     ACC
                MOV     R1,A
                POP     ACC
                MOV     R0,A
                RET

;-------------------------------------------------------------------------------
;FUNCTION:      CAL  ARCTAN(X)  X=CAL_TEMP(3_0),X=BINARY FLOAT
LDY_ARCTAN:
                PUSH    CAL_STATE1
                CLR     FLAG_TEMP4
                LCALL   LDY_ARCTANCTG
                POP     CAL_STATE1
                RET
;-------------------------------------------------------------------------------
;FUNCTION:      CAL  ARCCTG(X)  X=CAL_TEMP(3_0),X=BINARY FLOAT
LDY_ARCCTG:
                PUSH    CAL_STATE1
                SETB    FLAG_TEMP4
                LCALL   LDY_ARCTANCTG
                POP     CAL_STATE1
                RET

使用特权

评论回复
55
ldy216| | 2008-7-4 15:54 | 只看该作者

函数-4

QQ:184324486
超级大师LDY


;-------------------------------------------------------------------------------
;FUNCTION:      CAL   E^X=2.718281828^X     CAL_TEMP(3_0)=X
;               RETURN  BINARY  FLOAT  AT  CAL_TEMP3_0
LDY_EXP:
                MOV     A,R0
                PUSH    ACC
                MOV     A,R1
                PUSH    ACC

                PUSH    CAL_STATE1
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7
                PUSH    CAL_TEMP8
                PUSH    CAL_TEMP9
                PUSH    CAL_TEMPA
                PUSH    CAL_TEMPB
                PUSH    CAL_TEMPC
                PUSH    CAL_TEMPD
                PUSH    CAL_TEMPE
                PUSH    CAL_TEMPF
                PUSH    CAL_TEMPG
                PUSH    CAL_TEMPH
                PUSH    CAL_TEMPI
                PUSH    CAL_TEMPJ

                MOV     A,CAL_TEMP2
                JNZ     EXP_MINEXP
                MOV     A,CAL_TEMP1
                JNZ     EXP_MINEXP
                MOV     A,CAL_TEMP0
                JNZ     EXP_MINEXP
                MOV     CAL_TEMP0,#001H
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP3,#000H
                LJMP    EXIT_LDYEXP
EXP_MINEXP:
                LCALL   FLOAT_MINEXP
                MOV     R1,#000H
                MOV     A,CAL_TEMP3
                ADD     A,#018H
                MOV     R0,A
                JNB     ACC.7,EXP_INIT
                MOV     A,CAL_TEMP3
                JB      ACC.7,EXP_INIT
EXP_EXPOVER:
                MOV     A,CAL_TEMP2
                JNB     ACC.7,EXP_SETMAX
EXP_SETZERO:
                MOV     CAL_TEMP0,#000H
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP3,#000H
                LJMP    EXIT_LDYEXP
EXP_SETMAX:
                MOV     CAL_TEMP0,#0FFH
                MOV     CAL_TEMP1,#0FFH
                MOV     CAL_TEMP2,#07FH
                MOV     CAL_TEMP3,#07FH
                LJMP    EXIT_LDYEXP
EXP_INIT:
                MOV     A,R0
                JB      ACC.7,EXP_INITITEM
                MOV     R1,A
                MOV     CAL_TEMP3,#0E8H
EXP_INITITEM:
               ;X=CAL_TEMP(B-8)
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3

                MOV     CAL_TEMPC,#001H     ;SUM=CAL_TEMP(J_G)  ,ITEM=CAL_TEMP(F_C)
                MOV     CAL_TEMPG,#001H
                MOV     CAL_TEMPD,#000H
                MOV     CAL_TEMPH,#000H
                MOV     CAL_TEMPE,#000H
                MOV     CAL_TEMPI,#000H
                MOV     CAL_TEMPF,#000H
                MOV     CAL_TEMPJ,#000H

                MOV     R0,#000H
                MOV     R2,#00BH         ;END ITEM=X^11/11!
LOOP_EXP:
                INC     R0
                MOV     A,R0
                MOV     CAL_TEMP4,A
                MOV     CAL_TEMP5,#000H
                MOV     CAL_TEMP6,#000H
                MOV     CAL_TEMP7,#000H
                MOV     CAL_TEMP0,CAL_TEMPC
                MOV     CAL_TEMP1,CAL_TEMPD
                MOV     CAL_TEMP2,CAL_TEMPE
                MOV     CAL_TEMP3,CAL_TEMPF
                LCALL   FLOAT_DIV

                MOV     CAL_TEMP4,CAL_TEMP8
                MOV     CAL_TEMP5,CAL_TEMP9
                MOV     CAL_TEMP6,CAL_TEMPA
                MOV     CAL_TEMP7,CAL_TEMPB
                LCALL   FLOAT_MUL
                MOV     CAL_TEMPC,CAL_TEMP0
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPF,CAL_TEMP3

                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD

                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3

                DJNZ    R2,LOOP_EXP
                LCALL   FLOATTODOUBLE
LOOP_EXP_SQR:
                MOV     A,R1
                JZ      EXIT_EXP_SQR
                MOV     CAL_TEMP8,CAL_TEMP0
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3
                MOV     CAL_TEMPC,CAL_TEMP4
                MOV     CAL_TEMPD,CAL_TEMP5
                MOV     CAL_TEMPE,CAL_TEMP6
                MOV     CAL_TEMPF,CAL_TEMP7

                LCALL   DOUBLE_MUL
                DEC     R1
                LJMP    LOOP_EXP_SQR
EXIT_EXP_SQR:
                LCALL   DOUBLETOFLOAT
EXIT_LDYEXP:
                POP     CAL_TEMPJ
                POP     CAL_TEMPI
                POP     CAL_TEMPH
                POP     CAL_TEMPG
                POP     CAL_TEMPF
                POP     CAL_TEMPE
                POP     CAL_TEMPD
                POP     CAL_TEMPC
                POP     CAL_TEMPB
                POP     CAL_TEMPA
                POP     CAL_TEMP9
                POP     CAL_TEMP8
                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                POP     CAL_STATE1
                POP     ACC
                MOV     R1,A
                POP     ACC
                MOV     R0,A
                RET

使用特权

评论回复
56
ldy216| | 2008-7-4 15:56 | 只看该作者

函数-5

QQ:184324486
超级大师LDY

;-------------------------------------------------------------------------------
;FUNCTION:      CAL    LOG(X)=LN(X),X=BINARY Float
;               LOG(X)=
;               LOG(X0)+((X-X0)/X0)^1/1-((X-X0)/X0)^2/2
;                      +((X-X0)/X0)^3/3-((X-X0)/X0)^4/4
;                      +...
LDY_LOG:
                PUSH    ACC
                PUSH    PSW
                MOV     A,R0
                PUSH    ACC
                MOV     A,R1
                PUSH    ACC
                MOV     A,R2
                PUSH    ACC
                MOV     A,R3
                PUSH    ACC
                PUSH    CAL_STATE1
                PUSH    CAL_TEMP4
                PUSH    CAL_TEMP5
                PUSH    CAL_TEMP6
                PUSH    CAL_TEMP7
                PUSH    CAL_TEMP8
                PUSH    CAL_TEMP9
                PUSH    CAL_TEMPA
                PUSH    CAL_TEMPB
                PUSH    CAL_TEMPC
                PUSH    CAL_TEMPD
                PUSH    CAL_TEMPE
                PUSH    CAL_TEMPF
                PUSH    CAL_TEMPG
                PUSH    CAL_TEMPH
                PUSH    CAL_TEMPI
                PUSH    CAL_TEMPJ

                MOV     A,CAL_TEMP2
                JNB     ACC.7,LOG_ENABLE
                LJMP    EXIT_LDYLOG
LOG_ENABLE:
                LCALL   FLOAT_MINEXP
                MOV     A,CAL_TEMP3  ;WILL ADD 0X16
                MOV     R2,A
                MOV     CAL_TEMP7,#0FFH   ;MAKE  1<=X<2
                MOV     CAL_TEMP6,#0D2H
                MOV     CAL_TEMP5,CAL_TEMP2
                MOV     CAL_TEMP4,CAL_TEMP1
                MOV     CAL_TEMP3,CAL_TEMP0
                MOV     CAL_TEMP2,#000H
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP0,#000H
                MOV     R3,#000H
LOOP_LOG_SQR:
                ;X<1.1?
                CLR     C
                MOV     A,CAL_TEMP5
                SUBB    A,#01000110B
                JC      EXIT_LOG_SQR
                JNZ     LOG_SQR
                MOV     A,CAL_TEMP4
                SUBB    A,#01100110B
                JC      EXIT_LOG_SQR
                JNZ     LOG_SQR
                MOV     A,CAL_TEMP3
                SUBB    A,#01100110B
                JC      EXIT_LOG_SQR
                JNZ     LOG_SQR
                MOV     A,CAL_TEMP2
                SUBB    A,#01100110B
                JC      EXIT_LOG_SQR
                JNZ     LOG_SQR
                MOV     A,CAL_TEMP1
                SUBB    A,#01100110B
                JC      EXIT_LOG_SQR
                JNZ     LOG_SQR
                MOV     A,CAL_TEMP0
                SUBB    A,#01100110B
                JC      EXIT_LOG_SQR
LOG_SQR:
                LCALL   DOUBLE_SQUAREROOT
                INC     R3
                LJMP    LOOP_LOG_SQR
EXIT_LOG_SQR:
                CLR     C
                MOV     A,CAL_TEMP5
                SUBB    A,#040H
                MOV     CAL_TEMP5,A
                LCALL   DOUBLETOFLOAT
                ;泰勒逼迫中X0=1,让X趋于1+
                MOV     CAL_TEMP8,CAL_TEMP0    ;XX=(X-X0)/X0
                MOV     CAL_TEMPC,CAL_TEMP0    ;CAL_TEMP(F_C)=ITEM
                MOV     CAL_TEMPG,CAL_TEMP0    ;CAL_TEMP(J_G)=SUM
                MOV     CAL_TEMP9,CAL_TEMP1
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPA,CAL_TEMP2
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPB,CAL_TEMP3
                MOV     CAL_TEMPF,CAL_TEMP3
                MOV     CAL_TEMPJ,CAL_TEMP3

                MOV     A,CAL_TEMP2
                JNZ     LOG_INIT
                MOV     A,CAL_TEMP1
                JNZ     LOG_INIT
                MOV     A,CAL_TEMP0
                JNZ     LOG_INIT
                LJMP    LOG_ADD
LOG_INIT:
                MOV     R0,#007H
                MOV     R1,#001H
LOOP_LOG:
                INC     R1
                MOV     CAL_TEMP0,CAL_TEMP8
                MOV     CAL_TEMP1,CAL_TEMP9
                MOV     CAL_TEMP2,CAL_TEMPA
                MOV     CAL_TEMP3,CAL_TEMPB
                MOV     CAL_TEMP4,CAL_TEMPC
                MOV     CAL_TEMP5,CAL_TEMPD
                MOV     CAL_TEMP6,CAL_TEMPE
                MOV     CAL_TEMP7,CAL_TEMPF

                LCALL   FLOAT_MUL
                LCALL   BYTE3_NEGATIVE
                MOV     CAL_TEMPC,CAL_TEMP0
                MOV     CAL_TEMPD,CAL_TEMP1
                MOV     CAL_TEMPE,CAL_TEMP2
                MOV     CAL_TEMPF,CAL_TEMP3
                MOV     A,R1
                MOV     CAL_TEMP4,A
                MOV     CAL_TEMP5,#000H
                MOV     CAL_TEMP6,#000H
                MOV     CAL_TEMP7,#000H
                LCALL   FLOAT_DIV
                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD
                MOV     CAL_TEMPG,CAL_TEMP0
                MOV     CAL_TEMPH,CAL_TEMP1
                MOV     CAL_TEMPI,CAL_TEMP2
                MOV     CAL_TEMPJ,CAL_TEMP3
                DJNZ    R0,LOOP_LOG
LOG_ADD:
                MOV     A,CAL_TEMPJ
                ADD     A,R3
                MOV     CAL_TEMPJ,A
                ;CAL    N*LOG(2)
                ;CAL_TEMP(3_0)=N
                MOV     CAL_TEMP3,#000H
                MOV     A,R2
                JB      ACC.7,LOG_ADD_N
LOG_ADD_P:
                MOV     CAL_TEMP1,#000H
                MOV     CAL_TEMP2,#000H
                LJMP    LOG_ADD_1
LOG_ADD_N:
                MOV     CAL_TEMP1,#0FFH
                MOV     CAL_TEMP2,#0FFH
LOG_ADD_1:

                MOV     A,R2
                ADD     A,#016H
                MOV     CAL_TEMP0,A
                MOV     A,CAL_TEMP1
                ADDC    A,#000H
                MOV     CAL_TEMP1,A
                MOV     A,CAL_TEMP2
                ADDC    A,#000H
                MOV     CAL_TEMP2,A

                ;CAL_TEMP(7_4)=LOG(2)
                MOV     CAL_TEMP7,#0E9H
                MOV     CAL_TEMP6,#01011000B
                MOV     CAL_TEMP5,#10111001B
                MOV     CAL_TEMP4,#00001011B
                LCALL   FLOAT_MUL

                MOV     CAL_TEMP4,CAL_TEMPG
                MOV     CAL_TEMP5,CAL_TEMPH
                MOV     CAL_TEMP6,CAL_TEMPI
                MOV     CAL_TEMP7,CAL_TEMPJ
                LCALL   FLOAT_ADD

EXIT_LDYLOG:
                POP     CAL_TEMPJ
                POP     CAL_TEMPI
                POP     CAL_TEMPH
                POP     CAL_TEMPG
                POP     CAL_TEMPF
                POP     CAL_TEMPE
                POP     CAL_TEMPD
                POP     CAL_TEMPC
                POP     CAL_TEMPB
                POP     CAL_TEMPA
                POP     CAL_TEMP9
                POP     CAL_TEMP8
                POP     CAL_TEMP7
                POP     CAL_TEMP6
                POP     CAL_TEMP5
                POP     CAL_TEMP4
                POP     CAL_STATE1
                POP     ACC
                MOV     R3,A
                POP     ACC
                MOV     R2,A
                POP     ACC
                MOV     R1,A
                POP     ACC
                MOV     R0,A
                POP     PSW
                POP     ACC

                RET

使用特权

评论回复
57
linqing171| | 2008-7-8 12:57 | 只看该作者

以前调过8K的浮点库,汇编的,51的。

当时调的时候,就是把算法都看懂,当时真不知道他们怎么想出来的。

都是 计算+查表+插值。
精度在1/256都没有问题的。

印象里面,那个浮点库是从21ic下的。。。
里面sin cos ln什么的都有。

使用特权

评论回复
58
shaokai| | 2011-4-14 18:07 | 只看该作者
新手上路多多指教

使用特权

评论回复
59
numLiu| | 2011-4-14 19:42 | 只看该作者
mark

使用特权

评论回复
60
utopiaworld| | 2011-4-14 22:13 | 只看该作者
艹 当年哥发的这么老的帖子都被翻出来了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则