0

why sum2 result is 6?? ,here is the code

#if defined(__aarch64__)
    
        int tmp=0;
        int sum2=0;
        int a1=2;
           __asm__ __volatile__
        (
            "mov %0,3\n\t"         //tmp=3
            "add %1,%0,%2\n\t"     //sum2=tmp+a1=3+2 ???
            :"=r"(tmp),"=r"(sum2)
            :"r"(a1)
        );
    
    
           LOG_D(TAG,"a=%d\n",sum2);
#endif
Timothy Baldwin
  • 3,551
  • 1
  • 14
  • 23
  • The compiler chooses the same register for %0 and %2. It doesn't know that you overwrite %0 before using %2. https://stackoverflow.com/a/15819941/8422330 – prl Mar 13 '22 at 19:47
  • 1
    Does this answer your question? [When to use earlyclobber constraint in extended GCC inline assembly?](https://stackoverflow.com/questions/15819794/when-to-use-earlyclobber-constraint-in-extended-gcc-inline-assembly) – prl Mar 13 '22 at 19:48

0 Answers0