Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Figures

Figure 1 inlining.cpp
extern "C" int Goober( int x, float y );

int main(int argc, char * argv[] )
{
    float f = 2.3;
    int x = argc;

    x = Goober( x, f );

    return x+1;    
}
Figure 2 inlining2.cpp
extern "C" int Goober( int x, float y )
{
    if ( x > 1 )
        return x * y;
    return
        x;
}
Figure 3 Inlining_wiithout.lst
_main:
    mov         eax,dword ptr [esp+4]    ; Load 'x' (EAX) with argc
    push        40133333h                ; Push 'f' (2.3)
    push        eax                      ; push 'x'
    call        _Goober
    add         esp,8                    ; Clean up stack
    inc         eax                      ; Add 1 to function ret value
    ret

_Goober:
    mov         eax,dword ptr [esp+4]
    cmp         eax,1
    jle         0040102D
    fild        dword ptr [esp+4]
    fmul        dword ptr [esp+8]
    jmp         __ftol
    ret
Figure 4 Inlining.lst
_main:

    // int x = argc;    ('x' stored in EAX register here)
    mov         eax,dword ptr [esp+4]

    // if ( x > 1 )
    cmp         eax,1
    jle         00401018

    // return x*y;
    fild        dword ptr [esp+4]
    fmul        dword ptr [__real@40133333]
    call        __ftol2

    // return x+1;
    inc         eax
    ret
Figure 5 ccc.cpp
extern "C" __declspec(noinline)
int foo(int i, int *j, int *k, int l)
{
    *j = *k;
    *k = i + l;
    return i + *j + *k + l;
}

int main( int argc, char * argv[] )
{
    int i,j, k, l;

    l = i = argc;

    int x = foo( i, &j, &k, l );

    return x * argc;
}
Figure 6 ccc.lst
_foo:
    // k = EAX
    // j = ESI
    // l = EDI
    // i = EDX

    //     *j = *k;
    mov         ecx,dword ptr [eax]
    mov         dword ptr [esi],ecx

    //    *k = i + l;
    lea         ecx,[edi+edx]
    mov         dword ptr [eax],ecx

    //    return i + *j + *k + l;
    mov         eax,dword ptr [esi]    // *j
    add         eax,ecx                // *k sub-expression (from 
                                       // previous line)
    add         eax,edi                // l
    add         eax,edx                // i
    ret

_main:
    push        ecx                   // preserve ECX
    mov         edx,dword ptr [esp+8] // i =argc
    push        esi                   // preserve ESI
    push        edi                   // preserve EDI
    lea         eax,[esp+10h]         // &k
    lea         esi,[esp+8]           // &j
    mov         edi,edx               // l = i
    call        _foo
    imul        eax,edx               // multiply return value by argc
    pop         edi                   // restore previously preserved 
                                      // regs
    pop         esi
    pop         ecx
    ret
Figure 7 tls.cpp
__declspec(thread) int i = 1;

int main()
{
    i = 4;
    return i;
}
Figure 8 Tls_without.lst
_main:
    mov         eax,dword ptr [__tls_index]
    mov         ecx,dword ptr fs:[2Ch]
    mov         ecx,dword ptr [ecx+eax*4]
    push        4
    pop         eax
    mov         dword ptr [ecx+4],eax
    ret
Figure 9 Tls.lst
_main:
    mov         eax,dword ptr fs:[0000002Ch]
    mov         ecx,dword ptr [eax]
    mov         eax,4
    mov         dword ptr [ecx+8],eax
    ret
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.