Thread: Calling an Assembly Function

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    1

    Calling an Assembly Function

    I have a function _writeHexASCII in assembly language that needs to be called

    its takes two parameters (*int, unsigned long int)

    How do I declare it in C so I can use it?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    extern return_type calling_convention writeHexASCII(int* p, unsigned long int n);
    Take heed to note what the function returns and who cleans the stack (the function or the caller?).
    It may be tricky.

    Then again, the assembly needs to be declared so the linker can find it. I can't help on that point.
    Last edited by Elysia; 12-07-2007 at 02:51 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Code:
    extern void writeHexASCII(int *, unsigned long int);
    Link it.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't forget calling convention and return type (or does C have calling convention?).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    All languages have a calling convention. The question is, of course, if the assembler being called is following the standard C calling convention in that particular machine. If not, the next question is to figure out if the calling convention expected by the assembler can be achieved from the particular compiler.

    The calling convention determines:
    1. Who cleans up the stack - caller or callee.
    2. How parameters are passed, in registers (if so, how many registers and in which order) or on the stack. Also in which order the arguments are passed on the stack.
    3. Which registers the function can use directly, and which registers must be preserved by the callee.
    4. How the return value is returned to the caller, if there is a return value.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. calling functions & assembly code
    By Micko in forum C++ Programming
    Replies: 1
    Last Post: 02-25-2004, 03:27 PM