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

Why arguments are passed on registers instead of stacks in assembly output?

$
0
0

I am learning assembly language for 86-64.

I have learned that arguments are passed using the stacks. However, arguments have been passed using the registers, and one of them, edx is a volatile one. I am confused why values were not passed using stacks?

I used this site - https://godbolt.org/

I have written a following C code:-

int a,b=7,c=5,d=10;int add(int bTemp,int cTemp, int dTemp){    int temp = bTemp + cTemp + dTemp;    return temp;}int main(){    a = add(b,c,d);    return 0;}

It compiles to: -

a:        .zero   4b:        .long   7c:        .long   5d:        .long   10add(int, int, int):        push    rbp        mov     rbp, rsp        mov     DWORD PTR [rbp-20], edi        mov     DWORD PTR [rbp-24], esi        mov     DWORD PTR [rbp-28], edx        mov     edx, DWORD PTR [rbp-20]        mov     eax, DWORD PTR [rbp-24]        add     edx, eax        mov     eax, DWORD PTR [rbp-28]        add     eax, edx        mov     DWORD PTR [rbp-4], eax        mov     eax, DWORD PTR [rbp-4]        pop     rbp        retmain:        push    rbp        mov     rbp, rsp        mov     edx, DWORD PTR d[rip]        mov     ecx, DWORD PTR c[rip]        mov     eax, DWORD PTR b[rip]        mov     esi, ecx        mov     edi, eax        call    add(int, int, int)        mov     DWORD PTR a[rip], eax        mov     eax, 0        pop     rbp        ret

Viewing all articles
Browse latest Browse all 22102

Trending Articles



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