Skip to content

Commit 07b35a2

Browse files
committed
modify the inline assembly example according to upstream
1 parent b267569 commit 07b35a2

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Theory/linux-theory-3.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,25 +406,29 @@ The result, as expected:
406406
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:
407407

408408
```C
409-
#include <stdio.h>
410-
411-
unsigned long a = 1;
409+
unsigned long a = 10;
410+
unsigned long b = 20;
412411

413-
int main(void)
412+
void main(void)
414413
{
415-
unsigned long b;
416-
__asm__ ("movq %1,%0" : "=r"(b) : "r"(a));
417-
return b;
414+
__asm__ ("movq %1,%0" : "=mr"(b) : "rm"(a));
418415
}
419416
```
420417
421418
will use a memory operand:
422419
423420
```assembly
424-
0000000000400400 <main>:
425-
4004aa: 48 8b 05 6f 0b 20 00 mov 0x200b6f(%rip),%rax # 601020 <a>
421+
main:
422+
movq a(%rip),b(%rip)
423+
ret
424+
b:
425+
.quad 20
426+
a:
427+
.quad 10
426428
```
427429

430+
instead of direct usage of general purpose registers.
431+
428432
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).
429433

430434
Architecture specific constraints

0 commit comments

Comments
 (0)