32 bits 的BIN 到 BCD 换, 51 ASM 仅 272 周期
; SUB_BIN2BCD32: ;---------------------------------------------------- ; "二百五" 算法 DengMiao 2009-05-27 GuangZhou ; Input: bin 32: R7:R6:R5:R4 ; Output: Bcd : R7:R6:R5:R4:R3 ; 使用: R2..R7, A, B, C,AC,OV Stack:2 bytes ; Code: 133 bytes 周期: 272 ;---------------------------------------------------- ORG 000H AJMP START ORG 80H START: ; 1234567890 = &h4996 02D2 ; R7R6R5R4R3 R7R6 R5R4 MOV R7, #049H MOV R6, #096H MOV R5, #002H MOV R4, #0D2H ; SJMP L_TEST MOV R7, #0FFH MOV R6, #0FFH MOV R5, #0FFH MOV R4, #0FFH L_TEST: ; &hffffffff = 4,294,967,295 ACALL SUB_BIN2BCD32 L_STOP: SJMP L_STOP ;$
ORG 100H SUB_BIN2BCD32: ;---------------------------------------------------- ; "二百五" 算法 DengMiao 2009-05-27 GuangZhou ; Input: bin 32: R7:R6:R5:R4 ; Output: Bcd : R7:R6:R5:R4:R3 ; 使用: R2..R7, A, B, C,AC,OV Stack:2 bytes ; Code: 133 bytes 周期: 272 ;---------------------------------------------------- MOV B, R7 ACALL S_DIV250 XCH A, R5 ;XCH A, R6 ;MOV R2, A ; R7:00:00 *250 ; R2:00:00 *250 ; B:R5:R4 *1 ACALL S_DIV250B XCH A, R4 ; R7:R5:00 *250 XCH A, R6 ; R2:R3:00 *250 MOV R3, A ACALL S_DIV250 ; R7:R5:R4 *250 ; R2:R3:R6 *250 ; B *1 MOV A, R4 ADD A, R6 XCH A, R3 ADDC A, R5 XCH A, R7 ADDC A, R2 RRC A XCH A, R7 RRC A XCH A, R3 ; RRC A ; MOV R6, A ; RLC A ACALL S_999B ; R7:R3:R6 *500
XCH A, R7 ; R7 *BCD*100 RRC A MOV R5, A XCH A, B SWAP A ORL A, R2
XCH A, R3 ; R3 *1 BCD RRC A XCH A, R6 RRC A ;----------------------------- MOV R4, A ; R5:R6:R4 *1000 ACALL S_DIV250 ; XCH A, R4 ;XCH A, R6 ;MOV R2, A ACALL S_DIV250B ; R5:R4 *250 ; R2:R6 *250 ; B *1 MOV A, R6 ADD A, R4 XCH A, R5 ADDC A, R2 ; A:R5 RRC A XCH A, R5 RRC A MOV R4, A ;RLC A ACALL S_999C ; R5:R4 *500
SWAP A ADD A, B XCH A, R5 ; * 10000 BCD
RRC A MOV B, A
XCH A, R2 SWAP A ORL A, R7 XCH A, R4 ; *100 BCD RRC A MOV R6, A ;R2:R6 *1000*1000 ACALL S_DIV250 ; R2 *250 ; R6 *250 ; B*1 MOV A, R2 ADD A, R6 ;RRC A ;MOV R6, A ;RLC A ACALL S_999B XCH A, B SWAP A ADD A, R2 XCH A, R6 RRC A SWAP A ADD A, B MOV R7, A RET
S_999B: RRC A MOV R6, A S_999C: RLC A S_999: ;----------------------- ANL A, #3 ADD A, #(L_DB25-$-3) MOVC A, @A+PC MOV R2, A
MOV A, #10 XCH A, B DIV AB ADD A, R2 MOV R2, B MOV B, #10 DIV AB ; B*10 ; A*100 B*10BCD R6*1
RET
L_DB25: DB 0, 25, 50, 75 ;----------------------------------------- S_DIV250B: XCH A, R6 MOV R2, A
S_DIV250: ; B:R6 MOV A, #6 MUL AB ADD A, R6 XCH A, B ADDC A, #1 ; A:B MOV R6, A ADD A, R6 ADD A, R6 RLC A
;---------------------- ADD A, B JNC $+4 SJMP $+5 SUBB A, #6 DEC R6 ;-------------- MOV B, A RET
END
|
|