From 07b35a2d3f56ed5b7abb30fc792ae1cb4e86c8c4 Mon Sep 17 00:00:00 2001 From: Dongliang Mu Date: Fri, 20 Apr 2018 16:46:23 -0400 Subject: [PATCH] modify the inline assembly example according to upstream --- Theory/linux-theory-3.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Theory/linux-theory-3.md b/Theory/linux-theory-3.md index bed076b..14d670e 100644 --- a/Theory/linux-theory-3.md +++ b/Theory/linux-theory-3.md @@ -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: ```C -#include +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" : "=r"(b) : "r"(a)); - return b; + __asm__ ("movq %1,%0" : "=mr"(b) : "rm"(a)); } ``` will use a memory operand: ```assembly -0000000000400400
: - 4004aa: 48 8b 05 6f 0b 20 00 mov 0x200b6f(%rip),%rax # 601020 +main: + 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). Architecture specific constraints