In single-chip microcomputer often used to 16 (2) into the BCD code, although the C language programming is more convenient, but the assembly is often needed
Here is a 24-bit binary to the BCD code for example, where the BCD code is stored in a compressed manner, that is, 4-bit storage of a
/* Ingress parameter R1,R2,R3 holds 24-bit binary number, r1-bit maximum 8-bit exit parameter R4,R5,R6,R7 */mov R4, #0 mov R5, #0 mov R6, #0 mov R7, #0 CLR C MOV R0, #24//Shift count//above For initialization Loop:mov A,R3 RLC a mov r3,a mov a,r2 RLC a mov r2,a mov a,r1 RLC a MOV r1,a//mov a,r7 ADDC a,r7 DA A mov r7,a mov A,R6 ADDC a,r6 da 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 DJNZ r0,loop
If more digits, only need to register, you can use the address space memory,
And the number of shifts is correspondingly increased.