Inline asm

This is a discussion on Inline asm within the C++ Programming forums, part of the General Programming Boards category; I need help on calling a function in inline asm. Without asm it looks like: float fShotTime; float Position[3]; float ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    61

    Inline asm

    I need help on calling a function in inline asm.

    Without asm it looks like:
    float fShotTime;
    float Position[3];
    float Direction[3];
    int Type;
    int SelType;
    ZPostShotSp(fShotTime, Position, Direction, Type, SelType);

    The function i got from olly debugger:

    Code:
    004789E0  /$  64:A1 00000000  MOV EAX,DWORD PTR FS:[0]
    004789E6  |.  6A FF           PUSH -1
    004789E8  |.  68 179F5D00     PUSH Unpacked.005D9F17
    004789ED  |.  50              PUSH EAX
    004789EE  |.  64:8925 0000000>MOV DWORD PTR FS:[0],ESP
    004789F5  |.  83EC 10         SUB ESP,10
    004789F8  |.  53              PUSH EBX
    004789F9  |.  55              PUSH EBP
    004789FA  |.  56              PUSH ESI
    004789FB  |.  57              PUSH EDI
    004789FC  |.  68 33270000     PUSH 2733
    00478A01  |.  E8 FADC0400     CALL Unpacked.004C6700
    00478A06  |.  8B1D 7C735E00   MOV EBX,DWORD PTR DS:[<&kernel32.EnterCriticalSection>]        ;  ntdll.RtlEnterCriticalSection
    00478A0C  |.  83C4 04         ADD ESP,4
    00478A0F  |.  68 74876600     PUSH Unpacked.00668774                                         ; /pCriticalSection = Unpacked.00668774
    00478A14  |.  8BF8            MOV EDI,EAX                                                    ; |
    00478A16  |.  FFD3            CALL EBX                                                       ; \EnterCriticalSection
    00478A18  |.  8B35 70876600   MOV ESI,DWORD PTR DS:[668770]
    00478A1E  |.  85F6            TEST ESI,ESI
    00478A20  |.  74 0A           JE SHORT Unpacked.00478A2C
    00478A22  |.  8B46 08         MOV EAX,DWORD PTR DS:[ESI+8]
    00478A25  |.  A3 70876600     MOV DWORD PTR DS:[668770],EAX
    00478A2A  |.  EB 0C           JMP SHORT Unpacked.00478A38
    00478A2C  |>  6A 10           PUSH 10
    00478A2E  |.  E8 32741500     CALL Unpacked.005CFE65
    00478A33  |.  83C4 04         ADD ESP,4
    00478A36  |.  8BF0            MOV ESI,EAX
    00478A38  |>  68 74876600     PUSH Unpacked.00668774                                         ; /pCriticalSection = Unpacked.00668774
    00478A3D  |.  FF15 80735E00   CALL DWORD PTR DS:[<&kernel32.LeaveCriticalSection>]           ; \LeaveCriticalSection
    00478A43  |.  897424 18       MOV DWORD PTR SS:[ESP+18],ESI
    00478A47  |.  85F6            TEST ESI,ESI
    00478A49  |.  C74424 28 00000>MOV DWORD PTR SS:[ESP+28],0
    00478A51  |.  74 24           JE SHORT Unpacked.00478A77
    00478A53  |.  8B0D 30DC6600   MOV ECX,DWORD PTR DS:[66DC30]
    00478A59  |.  8B41 30         MOV EAX,DWORD PTR DS:[ECX+30]
    00478A5C  |.  8B50 18         MOV EDX,DWORD PTR DS:[EAX+18]
    00478A5F  |.  8B40 0C         MOV EAX,DWORD PTR DS:[EAX+C]
    00478A62  |.  8B0490          MOV EAX,DWORD PTR DS:[EAX+EDX*4]
    00478A65  |.  8B08            MOV ECX,DWORD PTR DS:[EAX]
    00478A67  |.  8BD1            MOV EDX,ECX
    00478A69  |.  894C24 10       MOV DWORD PTR SS:[ESP+10],ECX
    00478A6D  |.  52              PUSH EDX
    00478A6E  |.  8BCE            MOV ECX,ESI
    00478A70  |.  E8 DB170900     CALL Unpacked.0050A250
    00478A75  |.  EB 02           JMP SHORT Unpacked.00478A79
    00478A77  |>  33C0            XOR EAX,EAX
    00478A79  |>  83CD FF         OR EBP,FFFFFFFF
    00478A7C  |.  50              PUSH EAX
    00478A7D  |.  8BCF            MOV ECX,EDI
    00478A7F  |.  896C24 2C       MOV DWORD PTR SS:[ESP+2C],EBP
    00478A83  |.  E8 08370900     CALL Unpacked.0050C190
    00478A88  |.  68 90876600     PUSH Unpacked.00668790
    00478A8D  |.  FFD3            CALL EBX
    00478A8F  |.  8B35 8C876600   MOV ESI,DWORD PTR DS:[66878C]
    00478A95  |.  85F6            TEST ESI,ESI
    00478A97  |.  74 0A           JE SHORT Unpacked.00478AA3
    00478A99  |.  8B46 14         MOV EAX,DWORD PTR DS:[ESI+14]
    00478A9C  |.  A3 8C876600     MOV DWORD PTR DS:[66878C],EAX
    00478AA1  |.  EB 0C           JMP SHORT Unpacked.00478AAF
    00478AA3  |>  6A 18           PUSH 18
    00478AA5  |.  E8 BB731500     CALL Unpacked.005CFE65
    00478AAA  |.  83C4 04         ADD ESP,4
    00478AAD  |.  8BF0            MOV ESI,EAX
    00478AAF  |>  68 90876600     PUSH Unpacked.00668790                                         ; /pCriticalSection = Unpacked.00668790
    00478AB4  |.  FF15 80735E00   CALL DWORD PTR DS:[<&kernel32.LeaveCriticalSection>]           ; \LeaveCriticalSection
    00478ABA  |.  897424 1C       MOV DWORD PTR SS:[ESP+1C],ESI
    00478ABE  |.  85F6            TEST ESI,ESI
    00478AC0  |.  C74424 28 01000>MOV DWORD PTR SS:[ESP+28],1
    00478AC8  |.  74 31           JE SHORT Unpacked.00478AFB
    00478ACA  |.  8B4424 30       MOV EAX,DWORD PTR SS:[ESP+30]
    00478ACE  |.  8B48 08         MOV ECX,DWORD PTR DS:[EAX+8]
    00478AD1  |.  8B50 04         MOV EDX,DWORD PTR DS:[EAX+4]
    00478AD4  |.  8B00            MOV EAX,DWORD PTR DS:[EAX]
    00478AD6  |.  51              PUSH ECX
    00478AD7  |.  52              PUSH EDX
    00478AD8  |.  894C24 18       MOV DWORD PTR SS:[ESP+18],ECX
    00478ADC  |.  50              PUSH EAX
    00478ADD  |.  8BCE            MOV ECX,ESI
    00478ADF  |.  895424 20       MOV DWORD PTR SS:[ESP+20],EDX
    00478AE3  |.  894424 24       MOV DWORD PTR SS:[ESP+24],EAX
    00478AE7  |.  E8 C4190900     CALL Unpacked.0050A4B0
    00478AEC  |.  C706 34145F00   MOV DWORD PTR DS:[ESI],Unpacked.005F1434
    00478AF2  |.  C746 04 0600000>MOV DWORD PTR DS:[ESI+4],6
    00478AF9  |.  EB 02           JMP SHORT Unpacked.00478AFD
    00478AFB  |>  33F6            XOR ESI,ESI
    00478AFD  |>  56              PUSH ESI
    00478AFE  |.  8BCF            MOV ECX,EDI
    00478B00  |.  896C24 2C       MOV DWORD PTR SS:[ESP+2C],EBP
    00478B04  |.  E8 87360900     CALL Unpacked.0050C190
    00478B09  |.  6A 14           PUSH 14
    00478B0B  |.  E8 55731500     CALL Unpacked.005CFE65
    00478B10  |.  83C4 04         ADD ESP,4
    00478B13  |.  894424 1C       MOV DWORD PTR SS:[ESP+1C],EAX
    00478B17  |.  85C0            TEST EAX,EAX
    00478B19  |.  C74424 28 02000>MOV DWORD PTR SS:[ESP+28],2
    00478B21  |.  74 18           JE SHORT Unpacked.00478B3B
    00478B23  |.  8B4C24 34       MOV ECX,DWORD PTR SS:[ESP+34]
    00478B27  |.  8B51 08         MOV EDX,DWORD PTR DS:[ECX+8]
    00478B2A  |.  52              PUSH EDX
    00478B2B  |.  8B51 04         MOV EDX,DWORD PTR DS:[ECX+4]
    00478B2E  |.  8B09            MOV ECX,DWORD PTR DS:[ECX]
    00478B30  |.  52              PUSH EDX
    00478B31  |.  51              PUSH ECX
    00478B32  |.  8BC8            MOV ECX,EAX
    00478B34  |.  E8 77190900     CALL Unpacked.0050A4B0
    00478B39  |.  EB 02           JMP SHORT Unpacked.00478B3D
    00478B3B  |>  33C0            XOR EAX,EAX
    00478B3D  |>  50              PUSH EAX
    00478B3E  |.  8BCF            MOV ECX,EDI
    00478B40  |.  896C24 2C       MOV DWORD PTR SS:[ESP+2C],EBP
    00478B44  |.  E8 47360900     CALL Unpacked.0050C190
    00478B49  |.  68 A8746600     PUSH Unpacked.006674A8
    00478B4E  |.  FFD3            CALL EBX
    00478B50  |.  8B35 A4746600   MOV ESI,DWORD PTR DS:[6674A4]
    00478B56  |.  85F6            TEST ESI,ESI
    00478B58  |.  74 0B           JE SHORT Unpacked.00478B65
    00478B5A  |.  8B56 08         MOV EDX,DWORD PTR DS:[ESI+8]
    00478B5D  |.  8915 A4746600   MOV DWORD PTR DS:[6674A4],EDX
    00478B63  |.  EB 0C           JMP SHORT Unpacked.00478B71
    00478B65  |>  6A 10           PUSH 10
    00478B67  |.  E8 F9721500     CALL Unpacked.005CFE65
    00478B6C  |.  83C4 04         ADD ESP,4
    00478B6F  |.  8BF0            MOV ESI,EAX
    00478B71  |>  68 A8746600     PUSH Unpacked.006674A8                                         ; /pCriticalSection = Unpacked.006674A8
    00478B76  |.  FF15 80735E00   CALL DWORD PTR DS:[<&kernel32.LeaveCriticalSection>]           ; \LeaveCriticalSection
    00478B7C  |.  897424 1C       MOV DWORD PTR SS:[ESP+1C],ESI
    00478B80  |.  85F6            TEST ESI,ESI
    00478B82  |.  C74424 28 03000>MOV DWORD PTR SS:[ESP+28],3
    00478B8A  |.  74 0E           JE SHORT Unpacked.00478B9A
    00478B8C  |.  8B4424 38       MOV EAX,DWORD PTR SS:[ESP+38]
    00478B90  |.  50              PUSH EAX
    00478B91  |.  8BCE            MOV ECX,ESI
    00478B93  |.  E8 08150900     CALL Unpacked.0050A0A0
    00478B98  |.  EB 02           JMP SHORT Unpacked.00478B9C
    00478B9A  |>  33C0            XOR EAX,EAX
    00478B9C  |>  50              PUSH EAX
    00478B9D  |.  8BCF            MOV ECX,EDI
    00478B9F  |.  896C24 2C       MOV DWORD PTR SS:[ESP+2C],EBP
    00478BA3  |.  E8 E8350900     CALL Unpacked.0050C190
    00478BA8  |.  68 A8746600     PUSH Unpacked.006674A8
    00478BAD  |.  FFD3            CALL EBX
    00478BAF  |.  8B35 A4746600   MOV ESI,DWORD PTR DS:[6674A4]
    00478BB5  |.  85F6            TEST ESI,ESI
    00478BB7  |.  74 0B           JE SHORT Unpacked.00478BC4
    00478BB9  |.  8B4E 08         MOV ECX,DWORD PTR DS:[ESI+8]
    00478BBC  |.  890D A4746600   MOV DWORD PTR DS:[6674A4],ECX
    00478BC2  |.  EB 0C           JMP SHORT Unpacked.00478BD0
    00478BC4  |>  6A 10           PUSH 10
    00478BC6  |.  E8 9A721500     CALL Unpacked.005CFE65
    00478BCB  |.  83C4 04         ADD ESP,4
    00478BCE  |.  8BF0            MOV ESI,EAX
    00478BD0  |>  68 A8746600     PUSH Unpacked.006674A8                                         ; /pCriticalSection = Unpacked.006674A8
    00478BD5  |.  FF15 80735E00   CALL DWORD PTR DS:[<&kernel32.LeaveCriticalSection>]           ; \LeaveCriticalSection
    00478BDB  |.  897424 1C       MOV DWORD PTR SS:[ESP+1C],ESI
    00478BDF  |.  85F6            TEST ESI,ESI
    00478BE1  |.  C74424 28 04000>MOV DWORD PTR SS:[ESP+28],4
    00478BE9  |.  74 0E           JE SHORT Unpacked.00478BF9
    00478BEB  |.  8B5424 3C       MOV EDX,DWORD PTR SS:[ESP+3C]
    00478BEF  |.  52              PUSH EDX
    00478BF0  |.  8BCE            MOV ECX,ESI
    00478BF2  |.  E8 A9140900     CALL Unpacked.0050A0A0
    00478BF7  |.  EB 02           JMP SHORT Unpacked.00478BFB
    00478BF9  |>  33C0            XOR EAX,EAX
    00478BFB  |>  50              PUSH EAX
    00478BFC  |.  8BCF            MOV ECX,EDI
    00478BFE  |.  896C24 2C       MOV DWORD PTR SS:[ESP+2C],EBP
    00478C02  |.  E8 89350900     CALL Unpacked.0050C190
    00478C07  |.  57              PUSH EDI
    00478C08  |.  E8 43CE0400     CALL Unpacked.004C5A50
    00478C0D  |.  8B4C24 24       MOV ECX,DWORD PTR SS:[ESP+24]
    00478C11  |.  83C4 04         ADD ESP,4
    00478C14  |.  5F              POP EDI
    00478C15  |.  5E              POP ESI
    00478C16  |.  5D              POP EBP
    00478C17  |.  5B              POP EBX
    00478C18  |.  64:890D 0000000>MOV DWORD PTR FS:[0],ECX
    00478C1F  |.  83C4 1C         ADD ESP,1C
    00478C22  \.  C3              RETN


    How would i call ZPostShotSp(fShotTime, Position, Direction, 2, 7) in inline asm now? :/

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,628
    How about doing it in script first, then disassembe it to see how it does it?

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    I don't get what you mean..

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Well you could declare a function pointer

    Code:
    void (*ptrToZPostShotSp)( float, float*, float*, int, int );
    float fShotTime;
    float Position[3];
    float Direction[3];
    int Type;
    int SelType;
    ptrToZPostShotSp = // you figure out what to assign here
    
    // this calls it
    ptrToZPostShotSp (fShotTime, Position, Direction, Type, SelType);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Quote Originally Posted by Salem View Post
    Well you could declare a function pointer

    Code:
    void (*ptrToZPostShotSp)( float, float*, float*, int, int );
    float fShotTime;
    float Position[3];
    float Direction[3];
    int Type;
    int SelType;
    ptrToZPostShotSp = // you figure out what to assign here
    
    // this calls it
    ptrToZPostShotSp (fShotTime, Position, Direction, Type, SelType);
    Wouldn't that just be the same as
    Code:
    ZPostShotSp(fShotTime, Position, Direction, 2, 7)
    ?

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,628
    What I mean is, compile this code:
    Code:
    float fShotTime;
    float Position[3];
    float Direction[3];
    int Type;
    int SelType;
    
    void ZPostShotSp(float fShotTime, int Position, int Direction, int Type, int SelType);
    // Sorry, you don't say what type the varibles are.
    
    int main(void)
    {
       ZPostShotSp(0.0, NULL, NULL, 2, 7);
       // Now see what the disassembler says about this line!
       return 0;
    }
    
    void ZPostShotSp(float fShotTime, int Position, int Direction, int Type, int SelType)
    {
       return;
    }
    
    // End of file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM
  3. Inline asm
    By wavering in forum C Programming
    Replies: 2
    Last Post: 01-29-2002, 01:42 AM
  4. Inline asm - I love it!
    By wavering in forum C Programming
    Replies: 2
    Last Post: 01-08-2002, 01:19 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21