N DATA 30H NFACT EQU 31H TST: MOV N,#5 LCALL FACT0 MOV N,#8 LCALL FACT0 MOV N,#10 LCALL FACT0 STOP: LJMP STOP FACT0: MOV A,N LCALL FACT LCALL HBCD MOV R0,#NFACT MOV A,R1 MOV @R0,A INC R0 MOV A,R2 MOV @R0,A INC R0 MOV A,R3 MOV @R0,A INC R0 MOV A,R4 MOV @R0,A RET FACT: MOV R2,A MOV A,#1 MOV R3,A MOV R7,A CLR A MOV R5,A MOV R6,A FACT1: MOV A,R3 XRL A,R2 JNZ FACT2 RET FACT2: INC R3 MOV A,R7 MOV B,R3 MUL AB MOV R7,A MOV A,B XCH A,R6 MOV B,R3 MUL AB ADD A,R6 MOV R6,A CLR A ADDC A,B XCH A,R5 MOV B,R3 MUL AB ADD A,R5 MOV R5,A LJMP FACT1 HBCD: CLR A CLR A MOV R3,A MOV R4,A MOV R5,A MOV R2,#10H HB3: MOV A,R7 RLC A MOV R7,A MOV A,R6 RLC A MOV R6,A MOV A,R5 ADDC A,R5 DA A MOV R5,A MOV A,R4 ADDC A,R4 DA A MOV R4,A MOV A,R3 ADDC A,R3 MOV R3,A DJNZ R2,HB3 RET END