MSC-51 3字节和4字节浮点数计算程序,主要用于数据采集及上传,经过IEEE转换,在上位机直接显示.

;这是本人使用的MSC-51 3字节和4字节浮点数计算程序,主要用于数据采集及上传,经过IEEE转换,在上位机直接显示。
;本人还有热电阻和热电偶温度查表计算程序,有需要可EMAIL:majingsong1@2911.net

; FLOATING PROGRAM
;
;##########################################
;##########################################
;-----------------------------------------------
; IEEE754 FLOAT CONVERT TO 4 BYTES FLOAT
; INPUT: ((R0))((R0)+1)((R0)+2)((R0)+3) IEEE-754 FLOAT
; OUTPUT: R4 R5R6R7    4 BYTES FLOAT
;-----------------------------------------------
IEE_F:MOV    A,@R0
    JNZ    CON_0
    INC    R0
    MOV    A,@R0
    JNZ    CON_1
    INC    R0
    MOV    A,@R0
    JNZ    CON_2
    INC    R0
    MOV    A,@R0
    JNZ    CON_3

    DEC    R0
    DEC    R0
    DEC    R0
    RET
CON_3:DEC    R0
CON_2:DEC    R0
CON_1:DEC    R0
CON_0:CLR    FLAG_0
    INC    R0
    MOV    A,@R0
    RLC    A
    MOV    R5,A
    DEC    R0
    MOV    A,@R0
    RLC    A
    MOV    R4,A
    JNC    SA_IE
    SETB    FLAG_0
SA_IE: CLR    C
    MOV    A,R4
    SUBB    A,#7FH
    CLR    C
    INC    A

    ,C
    MOV    C,FLAG_0
    ,C
    MOV    R4,A
    MOV    A,R5
    SETB    C
    RRC    A
    MOV    R5,A
    INC    R0
    INC    R0
    MOV    A,@R0
    MOV    R6,A
    INC    R0
    MOV    A,@R0
    MOV    R7,A
    DEC    R0
    DEC    R0
    DEC    R0
    RET
;---------------------------------------------
; 4 BYTES FLOAT CONVERT TO IEEE754 FLOAT
; INPUT: ((R0)) R2R3R4 4 BYTES FLOAT
; OUTPUT: ((R1)) ((R1)+1) ((R1)+2) ((R1)+3)
; IEEE-754 FLOAT
;---------------------------------------------
F_IEE:
    INC    R0
    MOV    A, @R0
    MOV    R2, A
    INC    R0
    MOV    A, @R0
    MOV    R3, A
    INC    R0
    MOV    A, @R0
    MOV    R4, A
    DEC    R0
    DEC    R0
    DEC    R0

    MOV    A,R2
    JZ    ZERO_IEE
    MOV    A,@R0

    MOV    FLAG_0,C
    CLR    ACC.

    JC    F_FF
    DEC    A
    CLR    C
    ADD    A,#7FH
    LJMP    F_TR
F_FF:    CLR    C
    SUBB    A,#02H
F_TR:    MOV    C,FLAG_0
    RRC    A
    MOV    @R1,A
    INC    R1
    MOV    A,R2
    ,C
    MOV    @R1,A
    INC    R1
    MOV    A,R3
    MOV    @R1,A
    INC    R1
    MOV    A,R4
    MOV    @R1,A
FIEE_OFF:DEC R1
    DEC    R1
    DEC    R1
    RET
ZERO_IEE:MOV @R1,A
    INC    R1
    MOV    @R1,A
    INC    R1
    MOV    @R1,A
    INC    R1
    MOV    @R1,A
    SJMP    FIEE_OFF
;==========================================
; 2 BYTE MUL
; 0.R2R3 * 0.R4R5→0.R2R3R7
;------------------------------------------
D2_MUL: MOV    A, R3
    MOV    B, R5
    MUL    AB
    MOV    R7, B
    MOV    A, R3
    MOV    B, R4
    MUL    AB
    ADD    A, R7
    MOV    R7, A
    CLR    A
    ADDC    A, B
    MOV    R3, A
    MOV    A, R2
    MOV    B, R5
    MUL    AB
    ADD    A, R7
    MOV    A, R3
    ADDC    A, B
    MOV    R3, A
    , c
    MOV    A, R2
    MOV    B, R4
    MUL    AB
    ADD    A, R3
    MOV    R3, A
    CLR    A
    ADDC    A, B

    ADDC    A, #
    MOV    R2, A
    RET

;------------------------------
; 2 BYTE DIV
; 0.R2R3R7R6 / 0.R4R5→0.R2R3
; INPUT 0.R2R3  < 0.R4R5
;------------------------------
D2_DIV: MOV    A, R1
    PUSH    ACC
    MOV    B, #10H
A2O:    CLR    C
    MOV    A, R6
    RLC    A
    MOV    R6, A
    MOV    A, R7
    RLC    A
    MOV    R7, A
    MOV    A, R3
    RLC    A
    MOV    R3, A
    XCH    A, R2
    RLC    A
    XCH    A, R2
    , C
    CLR    C
    SUBB    A, R5
    MOV    R1, A
    MOV    A, R2
    SUBB    A, R4
    , A2S
    JC    A2R
A2S:    MOV    R2, A
    MOV    A, R1
    MOV    R3, A
    INC    R6
A2R:    DJNZ    B, A2O
    POP    ACC
    MOV    R1, A
    MOV    A, R7
    MOV    R2, A
    MOV    A, R6
    MOV    R3, A
    RET

;--------------------------------------
; 3 BYTE FLOAT LOAD
; ((R0))→R6,((R0)+1)→R2,((R0)+2)→R3
; ((R1))→R7,((R1)+1)→R4,((R0)+2)→R5
;--------------------------------------
F3_MLD: MOV    A, @R0
    MOV    R6, A
    INC    R0
    MOV    A, @R0
    MOV    R2, A
    INC    R0
    MOV    A, @R0
    MOV    R3, A
    DEC    R0
    DEC    R0
    MOV    A, @R1
    MOV    R7, A
    INC    R1
    MOV    A, @R1
    MOV    R4, A
    INC    R1
    MOV    A, @R1
    MOV    R5, A
    DEC    R1
    DEC    R1
    RET

;--------------------------------------
; 3 BYTE FLOAT STANDED
;--------------------------------------
F3_SDT: JC    M3A
    MOV    C, FLAG39
    , M3B
    MOV    A, R2
    RRC    A
    MOV    R2, A
    MOV    A, R3
    RRC    A
    MOV    R3, A
    INC    R6
    RET
M3B:    MOV    A, R4
    RRC    A
    MOV    R4, A
    MOV    A, R5
    RRC    A
    MOV    R5, A
    INC    R7
    RET
M3A:    MOV    A, R2
    JNZ    M3C
    CJNE    R3, #, M3D
    MOV    R6, #41H
M3E:    RET
, M3E

    MOV    A, R3
    RLC    A
    MOV    R3, A
    MOV    A, R2
    RLC    A
    MOV    R2, A
    CLR    PSW.
    DEC    R6
    SJMP    M3A
    RET

;--------------------------------------
; 3 BYTE FLOAT ADD OR SUB
; R6R2R3 + R7R4R5→R4R2R3
; R6R2R3 - R7R4R5→R4R2R3
; FLAG3A = 0 ADD FLAG3A = 1 SUB
;--------------------------------------
F3_ABP: MOV    A, R6

    MOV    FLAG38, C
    XRL    A, R7
    , SQ
    CPL    FLAG3A
    MOV    A, R6

    , C
    MOV    R6, A
    MOV    A, R7

    , C
    MOV    R7, A
SQ:    CLR    C
    MOV    A, R6
    SUBB    A, R7
    JZ    ST
    CLR    PSW.
    CLR    FLAG39
    , SW
    CJNE    R4, #00H, SE
    CJNE    R5, #00H, SE
ST:    JB    FLAG3A, SY
    MOV    A, R3
    ADD    A, R5
    MOV    R3, A
    MOV    A, R2
    ADDC    A, R4
    MOV    R2, A
    JNC    SD
    SETB    FLAG39
    CLR    C

    LCALL    F3_SDT
SD:    MOV    A, R6
    MOV    C, FLAG38
    , C
    XCH    A, R4
    MOV    R6, A
    RET
SW:    CJNE    R2, #00H, SF
    CJNE    R3, #00H, SF
    MOV    A, R7
    MOV    R6, A
    SJMP    ST

    CLR    C
    LCALL    F3_SDT
    SJMP    SQ
SY:    MOV    A, R3
    CLR    C
    SUBB    A, R5
    MOV    R3, A
    MOV    A, R2
    SUBB    A, R4
    MOV    R2, A
    JNC    SL
    CLR    A
    CLR    C
    SUBB    A, R3
    MOV    R3, A
    CLR    A
    SUBB    A, R2
    MOV    R2, A
    CPL    FLAG38
SL:    SETB    C
    SJMP    SF

;--------------------------------------
;3 BYTE FLOAT ADD
; ((R0))((R0)+1)((R0)+2) + ((R1))((R1)+1)
;     ((R1)+2)→R4R2R3
; FLAG3A = 0
;--------------------------------------
F3_ADD: CLR    FLAG3A
    LCALL    F3_MLD
    LCALL    F3_ABP
    RET

;--------------------------------------
; 3 BYTE SUB
; ((R0))((R0)+1)((R0)+2) -
; ((R1))((R1)+1)((R1)+2)→R4R2R3
; FLAG3A =  1
;--------------------------------------
F3_SUB: SETB    FLAG3A
    LCALL    F3_MLD
    LCALL    F3_ABP
    RET

;--------------------------------------
; 3 BYTE FLOAT MUL
; ((R0))((R0)+1)((R0)+2) *
; ((R1))((R1)+1)((R1)+2)→R4R2R3
;--------------------------------------
F3_MUL: LCALL  F3_MLD
    MOV    A, R6
    XRL    A, R7

    MOV    FLAG38, C
    LCALL    D2_MUL
    MOV    A, R7

    , C
    MOV    A, @R0
    ADD    A, @R1
    MOV    R6, A
    SETB    C
    LCALL    F3_SDT
    MOV    A, R6
    MOV    C, FLAG38
    , C
    MOV    R4, A
    RET

;--------------------------------------
; 3 BYTE FLOAT DIV
; ((R0))((R0)+1)((R0)+2) /
; ((R1))((R1)+1)((R1)+2)→R4(阶)R2R3
; C = 0 NORMAL ,C = 1 DIV BY 0
;--------------------------------------
F3_DIV: LCALL    F3_MLD
    MOV    A, R6
    XRL    A, R7

    MOV    FLAG38, C
    CLR    A
    MOV    R6, A
    MOV    R7, A
    CJNE    R4, #00H, TY
    CJNE    R5, #00H, TY
    SETB    C
    RET
TY:    MOV    A, R3
    SUBB    A, R5
    MOV    A, R2
    SUBB    A, R4
    JC    TU
    CLR    PSW.
    CLR    FLAG39
    LCALL    F3_SDT
    MOV    A, R7
    RRC    A
    MOV    R7, A
    CLR    C
    SJMP    TY
TU:    CLR    A
    XCH    A, R6
    PUSH    ACC
    LCALL    D2_DIV
    POP    ACC
    ADD    A, @R0
    CLR    C
    SUBB    A, @R1
    MOV    C, FLAG38
    , C
    MOV    R4, A
    CLR    C
    RET

;-------------------------------
; 3BYTE FLOAT STORE
; R4R2R3 TO (R1)(R1+1)(R1+2)
;-------------------------------
F3_STR: MOV    A, R4
    MOV    @R1, A
    INC    R1
    MOV    A, R2
    MOV    @R1, A
    INC    R1
    MOV    A, R3
    MOV    @R1, A
    DEC    R1
    DEC    R1
    RET

;--------------------------------
; 3 BYTE FLOAT SQRT
; F0 = 0 NORMAL ,F0 = 1 ERROR
;--------------------------------
F3_SQRT:MOV    A, @R0
    , BV
    MOV    @R1, A
    INC    R0
    INC    R1
    MOV    A, @R0
    MOV    @R1, A
    INC    R0
    INC    R1
    MOV    A, @R0
    MOV    @R1, A
    DEC    R0
    DEC    R0
    DEC    R1
    DEC    R1
BM:    LCALL    F3_DIV
    MOV    R6, A
    MOV    A, @R1
    MOV    R7, A
    INC    R1
    MOV    A, @R1
    MOV    R4, A
    INC    R1
    MOV    A, @R1
    MOV    R5, A
    DEC    R1
    DEC    R1
    CLR    FLAG3A
    LCALL    F3_ABP
    DEC    R4
    CLR    PSW.
    MOV    A, R4
    MOV    B, R7
    CJNE    A, B, BN
    MOV    A, R5
    SUBB    A, R3
    ANL    A, #0FCH
    MOV    R7, A
    MOV    A, R6
    SUBB    A, R2
    JNZ    BN
    CJNE    R7, #00H, BN

BN:    LCALL    F3_STR
    , BM
    RET

    RET

;------------------------------------
; 3 BYTE BIN TO 4 BYTE FLOAT
; INPUT ADDRESS (R0),OUTPUT ADDRESS (R1)
;------------------------------------
F3_BTF:MOV    A, #10H
    MOV    R2, A
    MOV    A, @R0
    MOV    R3, A
    INC    R0
    MOV    A, @R0
    MOV    R4, A
    DEC    R0
    MOV    A, R3
    ORL    A, R4
    JNZ    FRLN1
    MOV    R2, A
    MOV    R3, A
    MOV    R4, A
    JMP    FRLN2
FRLN1:    MOV    A, R3
    , FRLN2
    LCALL    FRL1
    SJMP    FRLN1
FRLN2:    INC    R1
    INC    R1
    MOV    A, R4
    MOV    @R1, A
    DEC    R1
    MOV    A, R3
    MOV    @R1, A
    DEC    R1
    MOV    A, R2
    CLR    ACC.
    CLR    ACC.
    MOV    @R1, A
    RET

FRL1:    CLR    C
    MOV    A, R4
    RLC    A
    MOV    R4, A
    MOV    A, R3
    RLC    A
    MOV    R3, A
    DEC    R2
    MOV    A, R2
    XRL    A, #0C0H
    JNZ    FRL1E
    MOV    R2, A
    MOV    R3, A
    MOV    R4, A
FRL1E:    RET

;------------------------------------
; 3 BYTE FLOAT BIN TO DEC
; INPUT DATA: FLAG3E = 0 1 <= DATA < 10
; FLAG3E = 1 FLAG3F = 0 0.2 <= DATA < 2
; FLAG3E = 1 FLAG3F = 1 0.4 <= DATA < 4
;------------------------------------
F3_BTD: MOV    A, @R0

    MOV    FLAG3C, C

    , C
    MOV    R6, A
    INC    R0
    MOV    A, @R0
    MOV    R2, A
    INC    R0
    MOV    A, @R0
    MOV    R3, A
    DEC    R0
    DEC    R0
    CJNE    R2, #00H, PA
    CJNE    R3, #00H, PA
    CLR    A
    MOV    @R1, A
    INC    R1
    MOV    @R1, A
    INC    R1
    MOV    @R1, A
    INC    R1
    MOV    @R1, A
    INC    R1
    MOV    @R1, A
    INC    R1
    MOV    @R1, A
PL:    DEC    R1
    DEC    R1
    DEC    R1
    DEC    R1
    DEC    R1
    RET
PA:    MOV    @R1, #00H
    JB    FLAG3E, PB
    DEC    @R1
PB:    INC    R1
    MOV    @R1, #01H
    JNB    FLAG3E, PD
    INC    @R1
    JNB    FLAG3F, PD
    INC    @R1
PD:    MOV    A, R6
    CLR    C
    SUBB    A, @R1
    JZ    PX
    , PE
PM:    DEC    @R1
    DEC    @R1
    DEC    @R1
    DEC    @R1
PZ:    MOV    A, R6
    CLR    C
    SUBB    A, @R1
    JZ    PY
    , PF
PQ:    JNB    FLAG3E, PG
    DEC    R6
    JNB    FLAG3F, PG
    DEC    R6
PG:    CJNE    R6, #00H, PH
    MOV    R6, #05H
    JNB    FLAG3E, PI
    MOV    R7, #01H
    JNB    FLAG3F, PJ
    INC    R7
PJ:    CLR    A
    CLR    C
PK:    XCH    A, R3
    RLC    A
    XCH    A, R3
    XCH    A, R2
    RLC    A
    XCH    A, R2
    RLC    A
    DJNZ    R7, PK
    DEC    R6
    MOV    @R1, A
    INC    R1
PI:    MOV    A, R3
    MOV    B, #0AH
    MUL    AB
    MOV    R3, A
    MOV    R7,B
    MOV    A, R2
    MOV    B, #0AH
    MUL    AB
    ADD    A, R7
    MOV    R2, A
    CLR    A
    ADDC    A, B
    MOV    @R1, A
    INC    R1
    DJNZ    R6, PI
    SJMP    PL
PX:    MOV    A, R2
    SUBB    A, #80H
    JC    PM
PE:    MOV    R5, #0CDH
    MOV    R4, #0CCH
    LCALL    D2_MUL
    MOV    A, R2
    , PN
    MOV    A, R7

    ORL    C, ACC.
    MOV    A, R3
    RLC    A
    MOV    R3, A
    MOV    A, R2
    RLC    A
    MOV    R2, A
    DEC    R6
PT:    MOV    A, R6
    ADD    A, #0FDH
    MOV    R6, A
    DEC    R1
    INC    @R1
    INC    R1
    SJMP    PD
TPS:    SJMP    PZ
PH:    MOV    A, R2
    RRC    A
    MOV    R2, A
    MOV    A, R3
    RRC    A
    MOV    R3, A
    INC    R6
    SJMP    PG
PY:    MOV    A, #0CBH
    CLR    C
    SUBB    A, R3
    MOV    A, #0CCH
    SUBB    A, R2
    JC    PQ
PF:    MOV    R4, #0A0H
    MOV    R5, #00H
    LCALL    D2_MUL
    MOV    A, R2
    , PR
    MOV    A, R7

    ORL    C, ACC.
    MOV    A, R3
    RLC    A
    MOV    R3, A
    MOV    A, R2
    RLC    A
    MOV    R2, A
    DEC    R6
PU:    MOV    A, R6
    ADD    A, #04H
    MOV    R6, A
    DEC    R1
    DEC    @R1
    INC    R1
    SJMP    TPS
PN:    MOV    A, R7
    , PT
    MOV    A, R3
    ORL    A, #01H
    MOV    R3, A
    SJMP    PT
PR:    MOV    A, R7
    , PU
    MOV    A, R3
    ORL    A, #01H
    MOV    R3, A
    SJMP    PU

;-----------------------------------
; 4 BITE FLOAT MUL
;((R0))((R0)+1)((R0)+2)((R0)+3)*
; ((R1))((R1)+1)((R1)+2)((R1)+3)
; TO R4R5R6R7
;-----------------------------------
F4_MUL: LCALL F4_LD
    INC    R1
    MOV    A, R0
    PUSH    ACC
    LCALL    D3_MUL
    POP    ACC
    MOV    R0, A
    DEC    R1
    MOV    A, R2

    , C
    MOV    A, @R0
    XRL    A, @R1

    MOV    FLAG38, C
    MOV    A, @R0
    ADD    A, @R1
    XCH    A, R0
    PUSH    ACC
    SETB    C
    LCALL    F4_STD
    POP    ACC
    XCH    A, R0
    MOV    C, FLAG38
    , C
    MOV    R4, A
    RET

;-----------------------------------
; 4 BITE FLOAT DIV
;((R0))((R0)+1)((R0)+2)((R0)+3)/
; ((R1))((R1)+1)((R1)+2)((R1)+3)
; TO R4R5R6R7,
; C=0 NORMAL, C=1 DIV BY 0
;-----------------------------------
F4_DIV: LCALL  F4_LD
    MOV    A, @R0
    XRL    A, @R1

    MOV    FLAG38, C
    CLR    A
    MOV    R5, A
    MOV    R6, A
    MOV    R7, A
    INC    R1
    CJNE    @R1, #00H, L4A
    INC    R1
    CJNE    @R1, #00H, L4B
    INC    R1
    CJNE    @R1, #00H, L4C
    DEC    R1
    DEC    R1
    DEC    R1
    SETB    C
    RET
L4C:    DEC    R1
L4B:    DEC    R1
L4A:    DEC    R1
    MOV    A, @R0
    XCH    A, R0
    INC    R1
    PUSH    ACC
L4E:    MOV    A, R4
    INC    R1
    INC    R1
    SUBB    A, @R1
    MOV    A, R3
    DEC    R1
    SUBB    A, @R1
    MOV    A, R2
    DEC    R1
    SUBB    A, @R1
    JC    L4D
    CLR    PSW.
    CLR    FLAG39
    LCALL    F4_STD
    MOV    A, R5
    RRC    A
    MOV    R5, A
    CLR    C
    SJMP    L4E
L4D:    MOV    A, R0
    PUSH    ACC
    LCALL    D3_DIV
    POP    ACC
    DEC    R1
    XCH    A, R0
    POP    ACC
    XCH    A, R0
    CLR    C
    SUBB    A, @R1
    MOV    C, FLAG38
    , C
    MOV    R4, A
    CLR    C
    RET

;-----------------------------------------
; 4 BITE FLOAT  LOAD
; ((R0)+1)((R0)+2)((R0)+3) TO R2R3R4
;-----------------------------------------
F4_LD:    INC    R0
    MOV    A, @R0
    MOV    R2, A
    INC    R0
    MOV    A, @R0
    MOV    R3, A
    INC    R0
    MOV    A, @R0
    MOV    R4, A
    DEC    R0
    DEC    R0
    DEC    R0
    RET

;-----------------------------------------
; 4 BITE FLOAT  ADD OR SUB
; ((R0))(R2)(R3)(R4) + ((R1))((R1)+1)((R1)+2)
;      ((R1)+3) TO R4R5R6R7
; ((R0))(R2)(R3)(R4) - ((R1))((R1)+1)((R1)+2)
;      ((R1)+3) TO R4R5R6R7
; FLAG3A=0 ADD, FLAG3A=1 SUB
;-----------------------------------------
F4_AB:    INC    R1
    MOV    A, @R1
    MOV    R5, A
    INC    R1
    MOV    A, @R1
    MOV    R6, A
    INC    R1
    MOV    A, @R1
    MOV    R7, A
    DEC    R1
    DEC    R1
    DEC    R1
    MOV    A, @R0

    MOV    FLAG38, C
    XRL    A, @R1
    , F4_ABT
    CPL    FLAG3A
F4_ABT:MOV    A, R0
    PUSH    ACC
    MOV    A, @R0

    , C
    MOV    R0, A
    MOV    A, R1
    PUSH    ACC
    MOV    A, @R1

    , C
    MOV    R1, A
F4_SDT1:CLR    C
    MOV    A, R0
    SUBB    A, R1
    JZ    F4_ABTI
    CLR    PSW.
    CLR    FLAG39
    , F4_ABX
    CJNE    R5, #00H, F4_ABG
    CJNE    R6, #00H, F4_ABG
    CJNE    R7, #00H, F4_ABG
    MOV    A, R0
    MOV    R1, A
F4_ABTI:JB    FLAG3A, F4_ABS
    MOV    A, R4
    ADD    A, R7
    MOV    R7, A
    MOV    A, R3
    ADDC    A, R6
    MOV    R6, A
    MOV    A, R2
    ADDC    A, R5
    MOV    R5, A
    JNC    F4_ABA
    SETB    FLAG39
    CLR    C

F4_ABL: LCALL F4_STD
    MOV    A, R1
    MOV    R0, A
F4_ABA: POP    ACC
    MOV    R1, A
    POP    ACC
    XCH    A, R0
    MOV    C, FLAG38
    , C
    XCH    A, R4
    RET
F4_ABX: CJNE    R2, #00H, F4_ABG1
    CJNE    R3, #00H, F4_ABG1
    CJNE    R4, #00H, F4_ABG1
    MOV    A, R1
    MOV    R0, A
    SJMP    F4_ABTI

F4_ABG1:CLR    C
    LCALL    F4_STD
    SJMP    F4_SDT1
F4_ABS: CLR    C
    MOV    A, R4
    SUBB    A, R7
    MOV    R7, A
    MOV    A, R3
    SUBB    A, R6
    MOV    R6, A
    MOV    A, R2
    SUBB    A, R5
    MOV    R5, A
    JNC    F4_ABS1
    CLR    A
    CLR    C
    SUBB    A, R7
    MOV    R7, A
    CLR    A
    SUBB    A, R6
    MOV    R6, A
    CLR    A
    SUBB    A, R5
    MOV    R5, A
    CPL    FLAG38
F4_ABS1:SETB    C
    CLR    PSW.
    LCALL    F4_STD
    SJMP    F4_ABA

;-----------------------------------------
; 4 BITE FLOAT  ADD
; ((R0))(R2)(R3)(R4) + ((R1))((R1)+1)((R1)+2)
;      ((R1)+3) TO R4R5R6R7
; FLAG3A=0 ADD
;-----------------------------------------
F4_ADD: CLR    FLAG3A
    LCALL    F4_LD
    LCALL    F4_AB
    RET

;-----------------------------------------
; 4 BITE FLOAT   SUB
; ((R0))(R2)(R3)(R4) - ((R1))((R1)+1)((R1)+2)
;      ((R1)+3) TO R4R5R6R7
; FLAG3A=1 SUB
;-----------------------------------------
F4_SUB: SETB    FLAG3A
    LCALL    F4_LD
    LCALL    F4_AB
    RET

;-----------------------------------------
; 4 BITE FLOAT  STANDED
; F0=0 R0R2R3R4
; F0=1 R1R5R6R7
;-----------------------------------------
F4_STD: JC    F4A
    MOV    C, FLAG39
    , F4B
    MOV    A, R2
    RRC    A
    MOV    R2, A
    MOV    A, R3
    RRC    A
    MOV    R3, A
    MOV    A, R4
    RRC    A
    MOV    R4, A
    INC    R0
    RET
F4B:    MOV    A, R5
    RRC    A
    MOV    R5, A
    MOV    A, R6
    RRC    A
    MOV    R6, A
    MOV    A, R7
    RRC    A
    MOV    R7, A
    INC    R1
    RET
F4A:    MOV    A, R5
    JNZ    F4C
    CJNE    R6, #00H, F4D
    CJNE    R7, #00H, F4D
F4E:    RET
, F4E    ; 0E7H

    MOV    A, R7
    RLC    A
    MOV    R7, A
    MOV    A, R6
    RLC    A
    MOV    R6, A
    MOV    A, R5
    RLC    A
    MOV    R5, A
    CLR    PSW.
    DEC    R0
    SJMP    F4A

;-----------------------------------
; 4 BYTE FLOAT STORE
; R4R5R6R7 TO (R0)(R0+1)(R0+2)(R0+3)
;-----------------------------------
F4_STR: MOV    A, R4
    MOV    @R0, A
    INC    R0
    MOV    A, R5
    MOV    @R0, A
    INC    R0
    MOV    A, R6
    MOV    @R0, A
    INC    R0
    MOV    A, R7
    MOV    @R0, A
    DEC    R0
    DEC    R0
    DEC    R0
    RET

;-------------------------------------------
; 3 BYTE DIV
; 0.R2R3R4R5R6R7 / ((R1))((R1)+1)((R1)+2)
;    TO (R0)(R0+1)(R0+2)(R0+3)
;-------------------------------------------
D3_DIV: MOV    R0, #18H
    INC    R1
    INC    R1
S3D:    CLR    C
    MOV    A, R7
    RLC    A
    MOV    R7, A
    MOV    A, R6
    RLC    A
    MOV    R6, A
    MOV    A, R5
    RLC    A
    MOV    R5, A
    MOV    A, R4
    RLC    A
    MOV    R4, A
    XCH    A, R3
    RLC    A
    XCH    A, R3
    XCH    A, R2
    RLC    A
    XCH    A, R2
    , C
    CLR    C
    SUBB    A, @R1
    DEC    R1
    MOV    A, R3
    SUBB    A, @R1
    DEC    R1
    MOV    B, A
    MOV    A, R2
    SUBB    A, @R1
    INC    R1
    INC    R1
    , S3A
    JC    S3B
S3A:    CLR    C
    MOV    R2, A
    MOV    A, R4
    SUBB    A, @R1
    MOV    R4, A
    MOV    R3, B
    INC    R7
S3B:    DJNZ    R0, S3D
    DEC    R1
    DEC    R1
    RET

;---------------------------------------
; 3 BYTE MUL
; 0.R2R3R4 * 0.((R1))((R1)+1)((R1)+2)
; TO R5R6R2R3R4
;---------------------------------------
D3_MUL: MOV    R0, #19H
    CLR    C
    CLR    A
    MOV    R5, A
    MOV    R6, A
    MOV    R7, A
K3B:    MOV    A, R5
    RRC    A
    MOV    R5, A
    MOV    A, R6
    RRC    A
    MOV    R6, A
    MOV    A, R7
    RRC    A
    MOV    R7, A
    XCH    A, R2
    RRC    A
    XCH    A, R2
    XCH    A, R3
    RRC    A
    XCH    A, R3
    XCH    A, R4
    RRC    A
    XCH    A, R4
    DJNZ    R0, K3A
    RET
K3A:    JNC    K3B
    INC    R1
    INC    R1
    ADD    A, @R1
    MOV    R7, A
    MOV    A, R6
    DEC    R1
    ADDC    A, @R1
    MOV    R6, A
    MOV    A, R5
    DEC    R1
    ADDC    A, @R1
    MOV    R5, A
    SJMP    K3B

;-------------------------------------------
; 功能:以e为底的浮点指数函数
;入口条件:操作数在TMP0中。使用TMP0,TMP1,TMP2
;出口信息:OV=0时,结果仍在TMP0中,OV=1时,溢出。
;影响资源:DPTR、PSW、A、B、R2~R7、位1EH、1FH  堆栈需求:6字节
;-------------------------------------------
F4_EXP:
    MOV    R1, #TMP1
    MOV    A, #01H        ; e(x) = 2(1.442695 * x)
    MOV    @R1, A
    INC    R1
    MOV    A, #0B8H
    MOV    @R1, A
    INC    R1
    MOV    A, #0AAH
    MOV    @R1, A
    INC    R1
    MOV    A, #3BH
    MOV    @R1, A

    MOV    R0, #TMP0
    MOV    R1, #TMP1
    LCALL    F4_MUL        ;进行加权运算
    MOV    R0, #TMP0
    LCALL    F4_STR

E20:
    MOV    R0, #TMP0
    MOV    A, @R0
    MOV    R4, A
    INC    R0
    MOV    A, @R0
    MOV    R5, A
    INC    R0
    MOV    A, @R0
    MOV    R6, A
    INC    R0
    MOV    A, @R0
    MOV    R7, A
    MOV    A, R5
    ORL    A, R6
    ORL    A, R7
    JNZ    EXP2
EXP1:
    MOV    R4, #01H        ;尾数为零,幂为1.000000
    MOV    R5, #80H
    MOV    R6, #00H
    MOV    R7, #00H
    CLR    OV
    RET
EXP2:
    MOV    R0, #TMP0
    MOV    A, @R0
    MOV    R4, A        ;将指数复制到工作区
    INC    R0
    MOV    A, @R0
    MOV    R5, A
    INC    R0
    MOV    A, @R0
    MOV    R6, A
    INC    R0
    MOV    A, @R0
    MOV    R7, A
    LCALL    INT
EXP4:
    MOV    A, R4
    , EXP5
    CLR    ACC.
    MOV    R0, A
    CLR    C
    MOV    R1, #00H
    MOV    A, R5
    PUSH    ACC
EXPJ1:    MOV    A, R5
    RLC    A
    MOV    R5, A
    MOV    A, R1
    RLC    A
    MOV    R1, A
    DJNZ    R0, EXPJ1
    POP    ACC
    MOV    R5, A
    MOV    A, R4
    , EXPJ2
    MOV    A, R1
    SJMP    EXP6
EXPJ2:    MOV    A, R1
    CPL    A
    INC    A
    SJMP    EXP6
EXP5:    MOV    A, #00H
EXP6:    PUSH    ACC    ;暂时保存之
    MOV    R0, #TMP1
    LCALL    F4_STR
    MOV    R0, #TMP0
    MOV    R1, #TMP1
    LCALL    F4_SUB    ;求指数的小数部分
    MOV    R0, #TMP0
    LCALL    F4_STR

    PUSH    DPH
    PUSH    DPL
    MOV    DPTR, #EXP_TABL
    MOV    TMP2, #41H
    , #00H
    , #00H
    , #00H
PLN1:    CLR    A        ;计算指数的小数部分的幂
    MOV    R0, #TMP1
    MOVC    A, @A+DPTR
    MOV    @R0, A
    INC    DPTR
    INC    R0
    CLR    A
    MOVC    A, @A+DPTR
    MOV    @R0, A
    INC    DPTR
    INC    R0
    CLR    A
    MOVC    A, @A+DPTR
    MOV    @R0, A
    INC    DPTR
    INC    R0
    CLR    A
    MOVC    A, @A+DPTR
    MOV    @R0, A
    INC    DPTR    ;指向下一个系数
    MOV    R0, #TMP2
    MOV    R1, #TMP1
    LCALL    F4_ADD    ;进行代数加法运算
    MOV    R0, #TMP2
    LCALL    F4_STR
    CLR    A    ;读取下一个系数的第一个字节
    MOVC    A, @A+DPTR
    CJNE    A, #40H, PLN2;是结束标志吗?
    POP    DPL
    POP    DPH
    POP    ACC        ;取出指数的整数部分
    ADD    A, R4        ;按补码加到幂的阶码上
    MOV    R4, A
    MOV    A, R4
    CLR    ACC.    ;幂的符号为正
    MOV    R4, A
    RET

PLN2:
    MOV    R0, #TMP0
    MOV    R1, #TMP2
    LCALL    F4_MUL    ;进行乘法运算
    MOV    R0, #TMP2
    LCALL    F4_STR
    LJMP    PLN1    ;继续下一项运算

EXP_TABL:
    DB    77H, 0B1H, 0C9H, 00H    ; 1.3564 * 10(-3)
    DB    7AH, 0A1H,  68H, 00H    ; 9.8514 * 10(-3)
    DB    7CH, 0E3H,  4FH, 00H    ; 0.055495
    DB    7EH, 0F5H, 0E7H, 00H    ; 0.24014
    DB    00H, 0B1H,  72H, 00H    ; 0.69315
    DB    01H,  80H,  00H, 00H    ; 1.000000
    DB    40H,  40H,  40H, 40H    ;结束
;-------------------------------------------
; (R4)R5R6R7
;-------------------------------------------
RLN:    MOV    A, R5        ;浮点数规格化
    ORL    A, R6        ;尾数为零否?
    ORL    A, R7
    JNZ    RLN1
    MOV    R4, #0C1H    ;阶码取最小值
    RET
RLN1:    MOV    A, R5
    , RLN2    ;尾数最高位为一否?
    CLR    C        ;不为一,左规一次
    LCALL    RL1
    SJMP    RLN        ;继续判断
RLN2:    CLR    OV        ;规格化结束
    RET
RL1:    MOV    A, R7        ;第一操作数左规一次
    RLC    A        ;尾数扩大一倍
    MOV    R7, A
    MOV    A, R6
    RLC    A
    MOV    R6, A
    MOV    A, R5
    RLC    A
    MOV    R5, A
    DEC    R4        ;阶码减一
    CJNE    R4, #0C0H, RL1E    ;阶码下溢否?
    CLR    A
    MOV    R5, A        ;阶码下溢,操作数以零计
    MOV    R6, A
    MOV    R7, A
    MOV    R4, #0C1H
RL1E:    CLR    OV
    RET
RR1:    MOV    A, R5    ;第一操作数右规一次
    RRC    A    ;尾数缩小一半
    MOV    R5, A
    MOV    A, R6
    RRC    A
    MOV    R6, A
    MOV    A, R7
    RRC    A
    MOV    R7, A
    INC    R4    ;阶码加一
    CLR    OV    ;清溢出标志
    CJNE    R4, #40H, RR1E    ;阶码上溢否?
    MOV    R4, #3FH    ;阶码溢出
    SETB    OV
RR1E:    RET

;-------------------------------------------
; 功能:浮点取整函数
;入口条件:操作数在[R0]中。
;出口信息:R4R5R6R7
;-------------------------------------------
FINT:
    MOV    A, @R0
    MOV    R4, A    ;阶存放在R4中
    INC    R0
    MOV    A, @R0    ;将尾数高字节存放在R5中
    MOV    R5, A
    INC    R0
    MOV    A, @R0    ;将尾数第二字节存放在R6中
    MOV    R4, A
    INC    R0
    MOV    A, @R0    ;将尾数第三字节存放在R7中
    MOV    R7, A
    DEC    R0    ;恢复数据指针
    DEC    R0
    DEC    R0
    LCALL    INT    ;在工作寄存器中完成取整运算
    RET

INT:    MOV    A, R5
    ORL    A, R6
    ORL    A, R7
    JNZ    INTA
    MOV    R4, #41H    ;尾数为零,阶码也清零,结束取整
    RET

INTA:    MOV    A, R4
    CLR    ACC.
    JZ    INTB    ;阶码为零否?
    , INTB;阶符为负否?
    CLR    ACC.
    CLR    C
    SUBB    A, #18H    ;阶码小于24否?
    JC    INTD
    RET        ;阶码大于24,已经是整数
INTB:    CLR    A      ;绝对值小于一,取整后正数为零,负数为负一
    MOV    R7, A
    MOV    R6, A
    MOV    R5, A
    MOV    R4, #41H
INTC:    RET

INTD:    CLR    F0    ;舍尾标志初始化
    MOV    A, R4
    CLR    ACC.
    MOV    R0, A
    CLR    A
    MOV    R1, A
    MOV    R2, A
    MOV    R3, A
    CLR    C
INTE:
    MOV    A, R7
    RLC    A
    MOV    R7, A
    MOV    A, R6
    RLC    A
    MOV    R6, A
    MOV    A, R5
    RLC    A
    MOV    R5, A
    MOV    A, R3
    RLC    A
    MOV    R3, A
    MOV    A, R2
    RLC    A
    MOV    R2, A
    MOV    A, R1
    RLC    A
    MOV    R1, A
    DJNZ    R0, INTE    ;阶码
    MOV    A, R4
    CLR    ACC.
    MOV    R0, A
    MOV    A, #18H
    CLR    C
    SUBB    A, R0
    MOV    R0, A
INTF:    CLR    C
    MOV    A, R3
    RLC    A
    MOV    R3, A
    MOV    A, R2
    RLC    A
    MOV    R2, A
    MOV    A, R1
    RLC    A
    MOV    R1, A
    DJNZ    R0, INTF
    MOV    A, R3
    MOV    R7, A
    MOV    A, R2
    MOV    R6, A
    MOV    A, R1
    MOV    R5, A
    RET

MCS51浮点计算程序的更多相关文章

  1. 关于C标准

    关于C标准 1. 前言 本文从英文 C-FAQ (2004 年 7 月 3 日修订版) 翻译而来.本文的 中文版权为朱群英和孙云所有. 本文的内容可以自由用于个人目的,但 是不可以未经许可出版发行. ...

  2. 程序设计入门-C语言基础知识-翁恺-第一周:简单的计算程序-详细笔记(一)

    目录 第一周:简单的计算程序 1.1 第一个程序 Hello World! 1.2 变量 1.3 计算 1.4 编程作业及课后讨论 第一周:简单的计算程序 1.1 第一个程序 Hello World! ...

  3. kernel 对浮点的支持

    http://blog.chinaunix.net/uid-22545494-id-316735.html 作者: Sam(甄峰)  sam_code@hotmail.com 一:早期ARM上的浮点模 ...

  4. ARM11 S3C6410 硬件浮点(VFP)实现

    http://blog.csdn.net/liujia2100/article/details/7459683 在调试一个代码时,编译能顺利编过.可是,就是不能执行.找了半天才发现,原来是浮点问题.由 ...

  5. Linux下VFP NEON浮点编译

    http://blog.csdn.net/liujia2100/article/details/27236477 NEON:SIMD(Single Instruction Multiple Data ...

  6. 硬浮点 VFP

    http://blog.chinaunix.net/uid-27875-id-3449290.html   编译器对VFP的支持一个浮点数操作最后是翻译成VFP指令,还是翻译成fpa,或者是softf ...

  7. VS中计算程序运行时间

    VS中计算程序运行的时间   http://bbs.csdn.net/topics/39068881 有时候在设计程序完了之后需要计算程序运行的时间. 这时候可以使用Windows的库函数 GetIi ...

  8. MCS-51系列特殊功能寄存器(摘录)

    MCS-51系列特殊功能寄存器(80H~FFH) 1. P0 (80H) P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 2.SP 栈指针(81H) 3.DPTR 数据 ...

  9. Java 入门 代码2浮点数据类型

    /** * 基本数据类型之浮点类型 */ public class DataTypeDemo2 { public static void main(String[] args) { double d1 ...

随机推荐

  1. JDKSDK配置

    变量名:ANDROID_HOME     变量值: E:\android-sdk_r11-windows\android-sdk_r11-windowsclsspath .;%JAVA_HOME%\l ...

  2. [AngularJS] Exploring the Angular 1.5 .component() method

    Angualr 1.4: .directive('counter', function counter() { return { scope: {}, restrict: 'EA', transclu ...

  3. soundPool和audiofocus

    audiofocus试验: 使用soundPool来写一个播放音频的porject. 资源初始化: setContentView(R.layout.activity_main); Button bt1 ...

  4. mysql将一个库中表的某几个字段插入到另一个库中的表

    insert into dbname1.tablename1(filed1,filed2,filed3) select filed1,filed2,filed3from dbname2.tablena ...

  5. 使用symbolicatecrash分析crash文件

    对于我们iOS开发者来说,最心碎的事莫过于苹果审核一个星期后上架app store,而第二天就报出闪退bug.一周前我刚经历过,而且最坑的是由于第一次做个人开发,经验不足,没有集成友盟的分析SDK,还 ...

  6. C#获取窗口,模拟按键操作

    C#获取窗口,模拟按键操作,实现计算器模拟操作.首先引用. using System.Runtime.InteropServices; 使用DllImport引入两个函数: // Get a hand ...

  7. C#时间戳的获取与转换方法

    /// <summary> /// 获取当前时间戳 /// </summary> /// <param name="bflag"></pa ...

  8. 使用CSS为内容设定特定的鼠标样式(cursor)介绍

    相信大家都知道我们的鼠标在网页中不同的元素中有不同的显示(例如 a 元素就显示为“箭头指针”),但是其实我们还可以自定义这些有趣的东西哦!今天“畅想资源”就来教大家如何使用CSS为内容设定特定的鼠标样 ...

  9. 【网络流#5】UVA 11082 最大流

    网络流题目最有意思的地方就是构图了,毕竟套模板每个人都会的 现在有一个矩阵,已知前i行元素之和a[i](1<=i<=n),前j列元素之和b[j](1<=j<=m),求一个可行的 ...

  10. canvas toDataUrl 跨域问题

    使用canvas 的 toDataUrl方法会遇到跨域问题 chrome 会报下面的错误: Uncaught SecurityError: Failed to execute 'toDataURL' ...