In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1.C language embedded assembly 1.1 embedded assembly syntax
1.2 embedded assembly example # include int main () {int result = 0; int input = 1; int a = 1; int b = 2 Asm volatile ("movl% 1,% 0\ n" / / specify interactive variables through placeholders: "= r" (result) / / output variables, interact with assembly: "r" (input) / / output variables, interact with assembly / / where r instructs the compiler to automatically associate general registers to variables) Printf ("result =% d\ n", result); printf ("input =% d\ n", input) Asm volatile ("movl% eax,% ecx\ n"movl%% ebx,% eax\ n"movl%% ecx,% ebx\ n": "= a" (a), "= b" (b) / / indicates that the a variable uses the a register: "a" (a), "b" (b)) Printf ("a =% d\ n", a); printf ("b =% d\ n", b); return 0;} 1.3 what did the compiler do?
For the above example, the compiler does the following:
1. Associate the result to an appropriate register
two。 Associate the input to an appropriate register
3. Indirect manipulation of variables through general registers
Note:
Assembly language does not support memory-to-memory direct operation, so registers should be used as intermediate roles.
1.4 description of commonly used qualifiers
1.5 use of system services
System services can be used directly through embedded assembly. Using kernel services through INT 80H
The 1.INT instruction is used to use the Linux kernel service (interrupt instruction)
2.80H is an interrupt vector number that is used to perform system calls
3. You can specify specific system calls and their parameters (such as sys_write services) through registers
1.6 use system services to complete printing char* s = "D.T.Software\ n"; int l = 13 Asm volatile ("movl $4,% eax\ n" / / "movl $1,% ebx\ n"movl% 0,% ecx\ n"movl% 1,% edx\ n"int $0x80\ n": "r" (s), "r" (l): "eax", "ebx", "ecx", "edx") 1.7 exit asm volatile using the system service executor ("movl $1,% eax\ n"movl $42,% ebx\ n"int $0x80\ n")
Note:
1. When embedded assembly, all parameters can be omitted except the assembly template.
two。 When the omitted parameter is in the middle, the corresponding delimiter ":" cannot be omitted
3. When the reserved list is omitted, the corresponding delimiter ":" can be omitted
4. When the optional parameter is omitted, a single% is prefixed before the register
When there are optional parameters, use two% as the prefix before the register
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.