这是本人使用的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
MOV R4,#0
MOV R5,#0
MOV R6,#0
MOV R7,#0
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
MOV C,ACC.7
MOV ACC.6,C
MOV C,FLAG_0
MOV ACC.7,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 C,ACC.7
MOV FLAG_0,C
CLR ACC.7
MOV C,ACC.6
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
MOV ACC.7,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
MOV PSW.5, c
MOV A, R2
MOV B, R4
MUL AB
ADD A, R3
MOV R3, A
CLR A
ADDC A, B
MOV C, PSW.5
ADDC A, #0
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
MOV PSW.5, C
CLR C
SUBB A, R5
MOV R1, A
MOV A, R2
SUBB A, R4
JB PSW.5, 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
JB PSW.5, 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, #0, M3D
MOV R6, #41H
M3E: RET
M3C: JB ACC.7, M3E
M3D: MOV C, PSW.5
MOV A, R3
RLC A
MOV R3, A
MOV A, R2
RLC A
MOV R2, A
CLR PSW.5
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 C, ACC.7
MOV FLAG38, C
XRL A, R7
JNB ACC.7, SQ
CPL FLAG3A
MOV A, R6
MOV C, ACC.6
MOV ACC.7, C
MOV R6, A
MOV A, R7
MOV C, ACC.6
MOV ACC.7, C
MOV R7, A
SQ: CLR C
MOV A, R6
SUBB A, R7
JZ ST
CLR PSW.5
CLR FLAG39
JB ACC.7, 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
SF: CLR PSW.5
LCALL F3_SDT
SD: MOV A, R6
MOV C, FLAG38
MOV ACC.7, 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
SE: CPL PSW.5
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 C, ACC.7
MOV FLAG38, C
LCALL D2_MUL
MOV A, R7
MOV C, ACC.7
MOV PSW.5, C
MOV A, @R0
ADD A, @R1
MOV R6, A
SETB C
LCALL F3_SDT
MOV A, R6
MOV C, FLAG38
MOV ACC.7, 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 C, ACC.7
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.5
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
MOV ACC.7, 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
JB ACC.7, 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.5
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
SETB PSW.5
BN: LCALL F3_STR
JNB PSW.5, BM
RET
BV: CLR PSW.5
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
JB ACC.7, FRLN2
LCALL
评论0