;SUB_BIN2BCD_N: ;---------------------------------------------------- ; "二百五" 算法 DengMiao 2009-05-04 GuangZhou ; Input: @R0: Input Bin data (LSB) ; A: BYTES of INPUT ; @R1: Output BCD Data (LSB) ; Output: @R1: Output BCD Data (LSB) ; @R0: Output BCD Data (MSB) ; A: BYTES OF OUTPUT ; R5: BYTES OF OUTPUT ; 使用: R0..R7, A, B, C,AC,OV,F0 Stack:2 bytes ; Code:243 bytes 周期: 200 bytes 0ffh 时, 559,379周期 ;---------------------------------------------------- InputBIN EQU 8H ; 200 BYTES .... 8 TO 207 (08H to 0CFH) InputLen EQU 200 ; 200 Bytes OutputBCD EQU 8H ; 241 BYTES .....8 TO 248 (08H to 0f8h) STACK EQU 249 ; 7 BYTES .. 249 TO 255 (0F9H to 0ffh) ;----------------------------------------- ORG 000H AJMP START ORG 80H START: MOV SP, #(STACK-1)
CLR A MOV PSW, A MOV R0, A CLR_RAM: MOV @R0, A ; MOV A, #0AAH ; FOR TEST DJNZ R0, CLR_RAM ;------------------------------------------ ; TEST DATA INPUT: 200 Bytes 0ffh MOV R0, #InputBin MOV R2, #InputLen MOV A, #0FFH ; 200 BYTES 0FFH LLLP_R2: MOV @R0, A INC R0 DJNZ R2, LLLP_R2 ;----------------------------------- ; CALL SUB MOV R0, #InputBin MOV A, #InputLen MOV R1, #OutputBCD ACALL SUB_BIN2BCD_N
L_STOP: SJMP L_STOP ;$
;------------------------------------------------- ORG 100H SUB_BIN2BCD_N: ;---------------------------------------------------- ; "二百五" 算法 DengMiao 2009-05-01 GuangZhou ; Input: @R0: Input Bin data (LSB) ; A: BYTES of INPUT ; @R1: Output BCD Data (LSB) ; Output: @R1: Output BCD Data (LSB) ; @R0: Output BCD Data (MSB) ; A: BYTES OF OUTPUT ; R5: BYTES OF OUTPUT ; 使用: R0..R7, A, B, C,AC,OV,F0 Stack:2 bytes ; Code:242 bytes 周期: 200bytes 0ffh==559,379周期 ;---------------------------------------------------- ACALL BIN2BCD_BYTE_NUM ; A == BCD LEN R6==BIN_LEN MOV R5, A ; BCD LEN MOV R2, A ; R2: BCD LEN MOV A, R6 XCH A, R1 ; R1: BIN LEN MOV R7, A ; R1_BAK SUBB A, R0 JZ L_R0_EQ_R1 MOV A, R7 JNC L_R1_GT_R0 MOV R1, A MOV A, R6 MOV R3, A LP_R3_COPY: MOV A, @R0 MOV @R1, A INC R0 INC R1 DJNZ R3, LP_R3_COPY SJMP L_R0_EQ_R1
L_R1_GT_R0: ADD A, R1 XCH A, R1 MOV R3, A ADD A, R0 MOV R0, A LP_R3_COPY_V: DEC R0 DEC R1 MOV A, @R0 MOV @R1, A DJNZ R3, LP_R3_COPY_V
L_R0_EQ_R1: MOV A, R7 ADD A, R6 MOV R0, A MOV A, R2 SUBB A, R6 MOV R3, A LP_R3_CPY: MOV @R0,#0 INC R0 DJNZ R3, LP_R3_CPY MOV A, R7 MOV R1, A MOV A, R2 RR A ANL A, #07FH MOV R3, A
LP_R3_SWAP: DEC R0 MOV A, @R1 XCH A, @R0 MOV @R1, A INC R1 DJNZ R3, LP_R3_SWAP ;--------------------------------------------- ; R7 -- BCD START ; R2 -- BCD LEN R6 -- BIN LEN ;-------------------------------------- MOV A, R7 MOV R0, A ADD A, R2 SUBB A, R6 MOV R7, A ;-------------------------------------- ; R0 -- BCD START ; R7 -- BIN START R6 -- BIN LEN ;-------------------------------------- CLR F0 MOV R4, #0FFH DEC R6 LP_R6: ;<<<<=============== MOV R2, #0 LP_R6B: MOV A, R6 MOV R3, A
MOV A, R7 INC R7 MOV R1, A
CLR A XCH A, @R1 INC R1 JNZ LP_R3B2 CJNE R6, #1, $ + 5 SJMP LP_R3B2 DJNZ R6, LP_R6B ;====================SJMP $ LP_R3B: XCH A, @R1 INC R1 LP_R3B2: ;-------------------------------- ; (R2 and 3):00 * 250 ; A:@R1 * 1 ;-------------------------------- MOV @R0, A ; MOV B, #6 MUL AB ADD A, @R1 XCH A, B ADDC A, #0 MOV @R1, A ADD A, @R1 ADD A, @R1 RLC A ADD A, B JNC $ + 5 ADD A, #6 INC @R1 ; @R0 * 250 @R1 *250 :A * 1 XCH A, @R1 ADD A, @R0 ; @R1 * 1 C:A * 250 XCH A, R2 ORL A, #11111100B ADDC A, #0 MOV B, A JNC L_NB2 MOV A, R1 LP_CA: DEC R1 XCH A, @R1 ADDC A, #0 XCH A, @R1 JC LP_CA MOV R1, A L_NB2: MOV A, R2 MOV C, B.0 RRC A MOV C, B.1 RRC A DJNZ R3, LP_R3B XCH A, @R1 MOV B, R2
; (B AND 3) * 250 + A*1 ANL B, #3 ; B * 250 + A ACALL SUB_999 DJNZ R6, LP_R6 ;----------------LP_R6_EXIT MOV A, @R1 MOV B, R6 ACALL SUB_999 MOV A, R1 XRL A, R0 JNZ L_EXIT_A MOV A, R4 MOV @R0, A INC R0 L_EXIT_A: DEC R0 MOV A, R1 INC A SUBB A, R5 MOV R1, A MOV A, R5 RET
;====================================== BIN2BCD_BYTE_NUM: ; INPUT: A == BIN BYTE NUM ; OUTPUT: R6 == BIN BYTE NUM ; A == BCD BYTE NUM ;----------------------------- MOV R6, A ; K = I * 84& (256 * 16) ; K = (I + K) 5 + I + 1 MOV B, #84 MUL AB MOV A, #5 XCH A, B ANL A, #0F0H SWAP A ADD A, R6 DIV AB ADD A, R6 INC A RET
;======================================== SUB_999: ; B * 250 + A * 1 MOV R3, A MOV A, #25 MUL AB XCH A, R3 MOV B, #10 DIV AB ; B * 1 ADD A, R3 MOV R3, B ; R3 * 1 MOV B, #10 DIV AB CJNE A, #10, L_NE10C L_EQ10C: INC @R1 MOV A, @R1 DEC R1 JZ L_EQ10C CLR A L_NE10C: ; R3 * 1 B*10 A*100 JBC F0, L_F0_1C SETB F0 CJNE R4, #0FFH, L_R4_NE255C MOV R4, A SJMP L_R4_NE255BC
L_R4_NE255C: XCH A, R4 MOV @R0, A INC R0
L_R4_NE255BC: MOV A, B SWAP A ADD A, R3 MOV @R0, A INC R0 RET ; R5:R4 BCD C = 0
L_F0_1C: SWAP A ADD A, B XCH A, R4 SWAP A ADD A, R3 SWAP A MOV @R0, A INC R0 RET ;============================================
END
|