call an assembly function from C

This is a discussion on call an assembly function from C within the C Programming forums, part of the General Programming Boards category; i need to call an assembly function in one file from a C function in another file, is this possible ...

  1. #1
    Registered User wazilian's Avatar
    Join Date
    Oct 2001
    Posts
    26

    Unhappy call an assembly function from C

    i need to call an assembly function in one file from a C function in another file, is this possible and if so how? i have been trying to use the _asm() function, but it keeps giving me errors. i need this to create an accurate (or close to it) delay of 10 milliseconds for a Motorala microcontroller using the Cosmic compiler. thanx in advance.
    wazilian
    King of Wazil

  2. #2
    Sayeh
    Guest
    If your compiler doesn't support inline assembler, then you need to use your assembler to create an object file (that's where your assembly language code has been 'assembled' into binary, linked, resolved, etc.)

    Once that's done, in your c program, you can dynamically allocate a block of RAM (a non-moving pointer) large enough to hold the assembly .obj contents. Once that's done, load the object code, and then simply jump to it, using a function pointer.

    This will require coercion.
    This will require typedefing a function pointer.
    This will require pulling and returning argument(s) off/on the stack, from your asm stub.
    This will require returning from your asm stub.
    This may require preserving and restoring a stackframe, in your asm stub, unless you are very careful.

    enjoy.

  3. #3
    Registered User wazilian's Avatar
    Join Date
    Oct 2001
    Posts
    26
    thanx, but can you give me a sample code on how to do this, i have a general idea, but i'm not sure, i haven't found much documentation on this. thanx in advance.
    wazilian
    King of Wazil

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM

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