简体   繁体   中英

Resetting gcc's asm inline input

How to ask gcc to reset an asm inline input value? %0 in the following example is not reset to 42 after the first loop. So when i = 1, %0 value is still 0 .

for (int i = 0; i < N; ++i)
  asm("label: substract_immediate_value %0,%0,1;"
      "compare_immediate_value %0,0;"
      "branch_not_equal label"
      : /* no outputs */
      : /* input */ "r" (42));

I've not tried this, but it looks right:

for (int i = 0; i < N; ++i)
  {
    int n = 42;
    asm("label: substract_immediate_value %0,%0,1;"
        "compare_immediate_value %0,0;"
        "branch_not_equal label"
        :  "+r" (n));
  }

I presume this is a simplified example, because I can't imagine why you wouldn't just code that in C. Indeed, it's a no-op.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM