51 Single chip microcomputer assembly multi-byte 16 (2) binary to BCD code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.