Re: return 64-bit int by identifier (was Re: return?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- Ed L Cashin <ecashin@uga.edu> wrote:
> Hi.  That sounds like a question about the C
> language, but assuming
> that you only care about gcc (since this is
> kernelnewbies), why not
> just check and see?
> 
>   ecashin@marblerye tmp$ cat test.c
>   #include <stdio.h>
>   
>   long long f(void)
>   {
>       long long i = 0x0123456789abcdefLL;
>   
>       return i;
>   }
>   
>   int main(void)
>   {
>       long long i = f();
>   
>       printf("0x%Lx\n", i);
>       return 0;
>   }
  The assembly equivalent of this code is
enlightening. 64 bit values are returned through the
%eax and %edx registers rather than through %eax
alone. Relevant portions are attached..

.globl f
        .type   f,@function
f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    $-1985229329, -8(%ebp)
        movl    $19088743, -4(%ebp)
        movl    -8(%ebp), %eax <--------- copy to eax
        movl    -4(%ebp), %edx <--------- and edx to
return it
        leave
        ret
----------
.globl main
        .type   main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        subl    %eax, %esp
        call    f
        movl    %eax, -8(%ebp)<--------- take up the 
        movl    %edx, -4(%ebp)<--------- return value
        subl    $4, %esp
        pushl   -4(%ebp)
        pushl   -8(%ebp)
        pushl   $.LC0
        call    printf
--------



=====
Regards,
Kiran Kumar Immidi

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux