Results 1 to 4 of 4

Thread: C TO asm [NASM]

  1. #1

    Thread Starter
    Hyperactive Member demon.KILER's Avatar
    Join Date
    Jul 2006
    Location
    I cannot remember !?
    Posts
    408

    C TO asm [NASM]

    I am stuck - i cannot find answer in google or any where else -

    how can I pass values to my C code from asm ??

    I am compiling my both C code and ASM code to .obj file and linking the mess together . but i cannot find a way pass values to my c code and return value
    Thx for help
    VS 2005 .....Framework SDK 3.0

    "Its mostly the brave one who choose to not fight"

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: C TO asm [NASM]

    The EAX register is commonly where values are stored on 32-bit machines once a function has returned.

    So,

    Code:
    ; ASM
    ASMFunction proc
    mov eax, 1234
    ASMFunction endp
    
    // C
    void CFunction()
    {
        int blah = ASMFunction();
    }
    Passing values to functions is simple enough.. you just need to make sure the data types are the same size/type:
    Code:
    ; ASM
    AddASM proc
    LOCAL arg1:DWORD,arg2:DWORD
    pop arg2
    pop arg1
    
    add arg1, arg2
    
    mov eax, arg1
    
    ret
    AddASM endp
    
    // C
    void AddC(int num1, int num2)
    {
        return AddASM(num1, num2);
    }
    chem
    Last edited by chemicalNova; Dec 30th, 2007 at 10:45 PM.

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Hyperactive Member demon.KILER's Avatar
    Join Date
    Jul 2006
    Location
    I cannot remember !?
    Posts
    408

    Re: C TO asm [NASM]

    THX
    how i pass values from my asm to my C code ??
    VS 2005 .....Framework SDK 3.0

    "Its mostly the brave one who choose to not fight"

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: C TO asm [NASM]

    ..the same way.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width