In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to embed assembly language in C language, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Some of the codes are as follows:
Static inline void RestoreLocalPSR (portLONG newMask) {_ _ asm__ volatile__ ("mtcr% 0, psr\ n": "r" (newMask): "memory");}
The function implements the function of writing the value of the input parameter newMask to the psr register to restore the scene.
C embedded assembly format
_ _ asm__ (
Assembly statement part
Output part
Input section
Damage description section
);
C embedded assembly description
1) C inline assembly begins with the keyword _ _ asm__ or asm. If you use the volatile keyword, it tells the compiler not to optimize subsequent code.
2) Assembly statement part: it can contain multiple assembly statements, with "\ n" or ";" between each statement, for example:
Asm volatile ("mfcr% 0, psr\ n"lsri% 0,16\ n"sextb% 0\ n": "= r" (vec):)
Note: operands in assembly statements can use placeholders to refer to C language variables. The name is as follows:% 0 ~ 1,.
2) output part: C variable modified in assembly language
3) input part: C variable input into assembly language as a parameter
Note: the output and input parts are for the input and output parameters of the assembly statement section. For example, if the assembly language uses variables to set registers, it uses the input part; if the assembly language reads values from the register and saves them to variables, it uses the output part.
4) damage description: tell the compiler which registers or memory are used.
5) each part is separated by ":". The assembly statement part is essential, and the other parts can be omitted. Example: asm ("nop") to implement a null operation.
After reading the above, do you have any further understanding of how to embed assembly language in C language? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.