Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22080

Why does GCC load into different registers when compiling with no optimization? [duplicate]

$
0
0

I have this line: int a = s - b * c; s, b and c are variables. And it generates the following code

    mov     eax, DWORD PTR [rbp-12]
    imul    eax, DWORD PTR [rbp-8]
    mov     edx, DWORD PTR [rbp-4]
    sub     edx, eax
    mov     eax, edx
    mov     DWORD PTR [rbp-28], eax

Why the GCC compiler don't just do everything on EAX register in this case? Wouldn't this have the same result?

   mov     eax, DWORD PTR [rbp-12]
   imul    eax, DWORD PTR [rbp-8]
   sub     eax, DWORD PTR [rbp-4]
   mov     DWORD PTR [rbp-28], eax

Viewing all articles
Browse latest Browse all 22080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>