我写了一个24位的二进制数到BCD码的转换程序,程序已经调试出来,可以正确运行。但总觉得效率低了点,求高手帮我改进一下。修改的目标是尽量缩短转换的时间。我写的程序最大执行数量是1200条左右。 #include<VRS51L3074_Keil.inc> Bin equ 40H ;二进制高位 ;41H ;42H BCD equ 30H ;存放转换后的千万位 ;31H ;存放转换后的百万位 ;32H ;存放转换后的十万位 ;33H ;存放转换后的万位 ;34H ;存放转换后的千位 ;35H ;存放转换后的百位 ;36H ;存放转换后的十位 ;37H ;存放转换后的个位 ORG 0000H LJMP main
ORG 0200H main: MOV 40H,#0A9H ;存放要转换的24位二进制数 MOV 41H,#08AH MOV 42H,#0C7H
MOV 30H,#00H MOV 31H,#00H MOV 32H,#00H MOV 33H,#00H MOV 34H,#00H MOV 35H,#00H MOV 36H,#00H MOV 37H,#00H
ACALL Loop1
NOP
NOP
AJMP $
Loop1: MOV R0,#Bin CJNE @R0,#98H,Judge11 INC R0 CJNE @R0,#96H,Judge12 INC R0 CJNE @R0,#80H,Judge12 INC 30H AJMP BRET Judge11: JC Loop2 SUB1: INC 30H
MOV A,42H SUBB A,#80H MOV 42H,A
MOV A,41H SUBB A,#96H MOV 41H,A
MOV A,40H SUBB A,#98H MOV 40H,A
AJMP Loop1
Judge12: JNC SUB1
Loop2: MOV R0,#Bin CJNE @R0,#0FH,Judge21 INC R0 CJNE @R0,#42H,Judge22 INC R0 CJNE @R0,#40H,Judge22 INC 31H AJMP BRET
Judge21: JC Loop3 SUB2: INC 31H
MOV A,42H SUBB A,#40H MOV 42H,A
MOV A,41H SUBB A,#42H MOV 41H,A
MOV A,40H SUBB A,#0FH MOV 40H,A
AJMP Loop2 Judge22: JNC SUB2
Loop3: MOV R0,#Bin CJNE @R0,#01H,Judge31 INC R0 CJNE @R0,#86H,Judge32 INC R0 CJNE @R0,#0A0H,Judge32 INC 32H AJMP BRET Judge31: JC Loop4 SUB3: INC 32H
MOV A,42H SUBB A,#0A0H MOV 42H,A
MOV A,41H SUBB A,#86H MOV 41H,A
MOV A,40H SUBB A,#01H MOV 40H,A AJMP Loop3 Judge32: JNC SUB3
Loop4: CLR C MOV R0,#Bin MOV A,@R0 JNZ SUB4 INC R0 CJNE @R0,#27H,Judge41 INC R0 CJNE @R0,#10H,Judge42 INC 33H AJMP BRET Judge41: JC Loop5 SUB4: INC 33H
MOV A,42H SUBB A,#10H MOV 42H,A
MOV A,41H SUBB A,#27H MOV 41H,A
MOV A,40H SUBB A,#00H MOV 40H,A
AJMP Loop4 Judge42: JNC SUB4
Loop5: MOV R0,#Bin INC R0 CJNE @R0,#03H,Judge51 INC R0 CJNE @R0,#0E8H,Judge52 INC 34H AJMP BRET Judge51: JC Loop6 SUB5: INC 34H
MOV A,42H SUBB A,#0E8H MOV 42H,A
MOV A,41H SUBB A,#03H MOV 41H,A
AJMP Loop5 Judge52: JNC SUB5 Loop6: CLR C MOV R0,#Bin INC R0 MOV A,@R0 JNZ SUB6 INC R0 CJNE @R0,#64H,Judge6 INC 35H AJMP BRET Judge6: JC Loop7 SUB6: INC 35H MOV A,42H SUBB A,#64H MOV 42H,A
MOV A,41H SUBB A,#00H MOV 41H,A
AJMP Loop6
Loop7: MOV R0,#Bin INC R0 INC R0 CJNE @R0,#0AH,Judge7 INC 36H AJMP BRET Judge7: JC Loop8 SUB7: INC 36H MOV A,42H SUBB A,#0AH MOV 42H,A AJMP Loop7 Loop8: MOV 37H,42H BRET: RET END |