200 bytes bin to BCD(十进数482位) 51 ASM 要693,351周期
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 BYTE .. 249 TO 255 (0F9H to 0ffh)
ORG 000H AJMP START ORG 30H START: MOV SP, #(STACK-1)
CLR A MOV PSW, A MOV R0, A CLR_RAM: MOV @R0, A 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 ; Output: @R1: Output BCD Data ; A: BYTES OF OUTPUT ; 使用: R0..R7, A, B, C,AC,OV,F0 Stack:2 bytes ; Code:260 bytes 周期: 200bytes 0ffh==693,351周期 ;---------------------------------------------------- ACALL BIN2BCD_BYTE_NUM ; A == BCD LEN R5==BIN_LEN MOV R2, A ; R2: BCD LEN MOV A, R5 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, R5 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, R5 MOV R0, A MOV A, R2 SUBB A, R5 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 ;--------------------------------------------- MOV A, R7 ADD A, R2 SUBB A, R5 DEC A MOV R1, A CLR F0 ; R1 = 43H ; R7=40H R2 = 14H R5=10H MOV R4, #0FFH DEC R5 LP_R5: ;<<<<=============== MOV A, R5 MOV R3, A ;DEC R3
LP_R5B: INC R1 MOV A, @R1 JNZ LP_R3B2 CJNE R3, #1, $ + 5 SJMP LP_R3B2 DEC R5 DJNZ R3, LP_R5B SJMP $ LP_R3B: MOV A, @R1 LP_R3B2: MOV B, #6 MUL AB INC R1 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 XCH A, @R1 XCH A, R0 MOV A, R1 XCH A, R0 LP_CA: DEC R0 ADDC A, @R0 MOV @R0, A CLR A JC LP_CA DJNZ R3, LP_R3B
LP_R3B_EXIT: MOV A, R5 ;0K INC A MOV R3, A CPL A INC A ADD A, R1 MOV R0, A MOV B, #0 MOV A, @R0 LP_R3C: MOV C, B.0 RRC A MOV B.0, C MOV C, B.1 RRC A MOV B.1, C INC R0 XCH A, @R0 DJNZ R3, LP_R3C ; OK ; (B AND 3) * 250 + A*1 ANL B, #3 ; B * 250 + A ACALL SUB_999 MOV A, R1 SUBB A, R5 MOV R1, A DJNZ R5, LP_R5 LP_R5_EXIT: ;----------------LP_R5_EXIT MOV A, @R1 MOV B, A INC R1 MOV A, @R1 ACALL SUB_999 MOV A, R1 SUBB A, R0 JZ L_EXIT_SUB INC R0 XCH A, R4 MOV @R0, A CJNE R4, #2, L_EXIT_SUB INC R0 MOV A, R6 MOV @R0, A L_EXIT_SUB: MOV A, R2 RET
;====================================== BIN2BCD_BYTE_NUM: ; INPUT: A == BIN BYTE NUM ; OUTPUT: R5 == BIN BYTE NUM ; A == BCD BYTE NUM ;----------------------------- MOV R5, 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, R5 DIV AB ADD A, R5 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_NE10 SETB C L_EQ10: CLR A ADDC A, @R0 MOV @R0, A DEC R0 JC L_EQ10 CLR A L_NE10: MOV R0, A MOV A, R7 XCH A, R0 ; R3 * 1 B*10 A*100 JBC F0, L_F0_1 SETB F0 CJNE R4, #0FFH, L_R4_NE255 MOV R4, A SJMP L_R4_NE255B L_R4_NE255: XCH A, R4 MOV @R0, A INC R0 INC R7 MOV A, R6 MOV @R0, A INC R7
L_R4_NE255B: MOV A, B SWAP A ADD A, R3 XCH A, R4 MOV R6, A RET ; R6:R4 BCD C = 0
L_F0_1: SWAP A ADD A, B XCH A, R3 SWAP A ADD A, R6 XCH A, R4 ; R3:R4 BCD MOV @R0, A INC R7 MOV A, R3 MOV R6, A ; R6:R4 BCD C=0 RET
END |
|