Thread: function-call overhead... real? or not?

  1. #16
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    no problem.

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    ...but in inline assembly you can access the heap variable as well as the stack ones. However when mixing pure assembler with C modules it gets a little more difficult than that.


    Code:
    extern "C" DWORD Add32(DWORD dwVal1,DWORD dwVal2);
     
     
    int main(void)
    {
    DWORD dwValue=Add(300,10000);
     
    return(0); 
    }
    TASM
    Code:
    .386
    ...
    ...
    public Add32
     
    _Add32 proc
    ARG: DWORD dwVal1,DWORD dwVal2
     
    push ebp
    mov ebp,esp
     
    mov eax,dwVal1
    add eax,dwVal2
     
    pop ebp
     
    ret
     
    _Add32 endp
    Now this code should work correctly since everything is passed via the stack to Add32. But if you wanted to be able to access a global DWORD in C from assembly you would have to declare the variable in asm as well and specify that it was defined externally to the asm module. In C you would simply declare it as normal.

    It's absolutely ridiculous to even try this because I cannot fathom why you would want to alter a global C variable inside of a pure assembly module. But the same thing also holds true for structs. You pass the address or retrieve the address. Retrieving it requires that the struct be declared somewhere in the asm source, otherwise the asm module has no way of knowing what the struct is. As well the data alignment of the 2 structs (the C struct and the asm struct) must be identical or serious memory problems will occur.

    Best bet is to pass a pointer to any asm function via the stack and access the variable via offsets from ebp and create locals relative to esp or in memory. I recommend using the stack. And there are ways to poke around the code segment and change what CS:EIP points to but since that is not in the realm of well-behaved code I will not explain it.
    Last edited by VirtualAce; 12-20-2004 at 01:14 AM.

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah everything you mention here seems to have been my experience. And yeah I'm aware of playing with CS:EIP and the dangers that it can cause. And I had an understanding of what just not where. Thanks for the extra depth, the particulars of this are things I'm well aware of it was just a small gap in what i knew that needed filling.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM