Article 3 BCD code adjustment

Source: Internet
Author: User

BCD code adjustment commands are available in both x86 assembly and MCS-51 instruction sets. This blog post will talk about how to adjust the BCD code.

Related information.

 

1. The BCD code is a decdecdecdecimal number in computer format.

We have always said that computers can only represent 0 and 1 binary, which is undoubtedly correct. However, people are familiar with the decimal number.

To cater to the convenience of people, the 8421bcd code is used to represent the decimal number. Of course, BCD code is also expressed in binary values 0 and 1. So,

It should be noted that the computer here indicates that the decimal number is more of a logical concept, but it is also such a logical concept.

So that the BCD code can be used in the command to represent the decimal number, for example, in the Add or sub command. This brings us

Then.

 

II. (A) = 56 h, (R5) = 67 h. Add a, R5, da. (MCS-51 Instruction Set)

Da is the decimal Adjustment Command in 51.

First, we have to solve a problem. Are 56 h and 67h hexadecimal numbers or 10 hexadecimal numbers?

Anyone who has experience in assembly programming should be able to understand this issue well. Which of the 56 H and H is the hexadecimal number is not your decision,

It's not my decision. It isProgramAssigned by members based on the actual application scenario. In other words, programmers say it is hexadecimal, And it is hexadecimal.

It is 10-in-10. As long as programmers can understand and handle properly. In this example, 56 h, 67 h

It is the decimal number, because da a exists.

 

3. Why are adjustments required?

The computer does not understand what is 8421bcd in decimal format or normal hexadecimal format. It is a binary operation by default. For example

In the above example, 56 H + 67 h = 0bdh, which is obviously correct as a hexadecimal addition. If it is wrong, it is not a hexadecimal addition. It is a decimal addition.

System addition. In other words, the program changes its meaning to decimal, and the computer still performs hexadecimal computation, resulting in an error in the result. However,

The computer can get the correct result through simple adjustment.

A more intuitive explanation can be as follows:

8421bcd is used to represent 0-9, and the six numbers 1010, 1011, 1100, 1101, 1110 are not used. In decimal operation

Once these six numbers are displayed, they are incorrect and need to be adjusted.

 

4. What is the difference between the secondary carry mark AF and the lower four digits of Al? What is the difference between the secondary carry mark CF and the lower four digits of Al? (X86)

AF = 1 is it true that the four lower bits of Al must be greater than 9, and AF = 0 is it true that the four lower bits of Al must be smaller than 9? The same is true for CF and Al.

Problem.

First, let's look at the DAA Adjustment CommandAlgorithm:

 
If (Al four-digit lower> 9 | AF = 1) thenal = Al + 6; AF = 1; endifif (Al four-digit higher than 9 | cf = 1) thenal = Al + 60 h; cf = 1; endif

Therefore, the above questions can be answered. The relationship between AF = 1 and the size of Al 4-bit low and 9 is not necessarily related. Similarly, cf = 1 and Al Gao Si

The relationship between BITs and 9 is also the same.

For example:

1100 + 0100 = 10000, al low four digits are 0, but AF = 1, you need to add 6 adjustments.

 

 

 

 

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.