mirror of
https://github.com/0xAX/linux-insides.git
synced 2024-12-22 14:48:08 +00:00
add better inline assembler example
This commit is contained in:
parent
f3f7cc503c
commit
3c83a2257a
@ -406,25 +406,29 @@ The result, as expected:
|
|||||||
All of these constraints may be combined (so long as they do not conflict). In this case the compiler will choose the best one for a certain situation. For example:
|
All of these constraints may be combined (so long as they do not conflict). In this case the compiler will choose the best one for a certain situation. For example:
|
||||||
|
|
||||||
```C
|
```C
|
||||||
#include <stdio.h>
|
unsigned long a = 10;
|
||||||
|
unsigned long b = 20;
|
||||||
|
|
||||||
unsigned long a = 1;
|
void main(void)
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
{
|
||||||
unsigned long b;
|
__asm__ ("movq %1,%0" : "=mr"(b) : "rm"(a));
|
||||||
__asm__ ("movq %1,%0" : "=r"(b) : "r"(a));
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
will use a memory operand:
|
will use a memory operand:
|
||||||
|
|
||||||
```assembly
|
```assembly
|
||||||
0000000000400400 <main>:
|
main:
|
||||||
4004aa: 48 8b 05 6f 0b 20 00 mov 0x200b6f(%rip),%rax # 601020 <a>
|
movq a(%rip),b(%rip)
|
||||||
|
ret
|
||||||
|
b:
|
||||||
|
.quad 20
|
||||||
|
a:
|
||||||
|
.quad 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
instead of direct usage of general purpose registers.
|
||||||
|
|
||||||
That's about all of the commonly used constraints in inline assembly statements. You can find more in the official [documentation](https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html#Simple-Constraints).
|
That's about all of the commonly used constraints in inline assembly statements. You can find more in the official [documentation](https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html#Simple-Constraints).
|
||||||
|
|
||||||
Architecture specific constraints
|
Architecture specific constraints
|
||||||
|
Loading…
Reference in New Issue
Block a user