C51 syntax error log (1)

Source: Internet
Author: User

Today, when writing code, I found a very easy mistake.

Code

Void main ()
{
Unsigned int test;
Test = 0x02;
If (Test & 0x02 = 0x02)

{
Test = 0x02;
}
Else
{
Test = 0x02;
}
}

The red code is used to determine whether the second digit in the test variable is 1. However, after compilation, it is found that the assembly language of this Code is

C: 0x0011 EF mov A, r7
C: 0x0012 30e001 JNB 0xe0. 0, C: 0016

This is obviously in the judgment of the test variable's second bit.

Later I found that the Code must be changed

If (Test & 0x02) = 0x02)

The compilation result is correct.


 

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.