Search code examples
cassemblyx86header-files

How to combine assembly functions in .h file?


Might be a duplicate but i wasn't able to find a answer for my question.

Usually if you want to import multiple functions from different c files in one main class, one would make a .h file and list up all functions from the .c sources.

My problem is, that all functions are wridden in .asm files. I used extern void asmFunc(int i, char c); to use the function in further code, but they become more and more and i don't want to end up with 200 of those extern lines at the beginning of my main. How can i create a library.h with all assembly functions so i can just write #include "library.h" at the beginning of my main class?

EDIT: I think i didn't give enough specific information:

  • I use MINGW gcc and NASM to compile c and asm files
  • I have to compile all files to .o first so i can match them
  • The first answer i got didn't work because my compile chain is a bit complicated thanks to the restrictions i have on Windows (i want Linux back)

It looks like this: I got a folder containing three folders with seperated library-like structures: bwt (basic window toolkit), io and std (stuff like strlen) They are compiled into bwt.o io.o and std.o.

Now i want to make a .h file for each of them so i can #include "bwt.h" in all kernel classes which need them. How do i get gcc to realize, that all functions in bwt.h are defined in bwt.o?


Solution

  • Since you have a .o file, it doesn't matter that the source for those routines is assembly. As long as you know how to call them as C functions that's what matters.

    So put all of your extern declarations for the assembly functions in library.h, then #include "library.h" in your main file. Then you can link them.

    gcc -c main.c
    gcc -o program main.o asmfunctions.o