add better inline assembler example

pull/589/head
Alexander Kuleshov 6 years ago
parent f3f7cc503c
commit 3c83a2257a
No known key found for this signature in database
GPG Key ID: EE88CAC52D66AC9B

@ -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;
int main(void) void 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…
Cancel
Save