MSC-51 3字节和4字节浮点数核算程序,首要用于数据收集及上传,通过IEEE转化,在上位机直接显现。
;这是自己运用的MSC-51 3字节和4字节浮点数核算程序,首要用于数据收集及上传,通过IEEE转化,在上位机直接显现。
; 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