Page 1 of 1

synchronize NASM and C Code

Posted: Fri Mar 01, 2002 6:48 am
by roswell
Hi, I'm designing an OS using NASM and C code.
Sometimes I had trouble with "synchronisation" between C structures and NASM offsets.

In order to avoid this problem, I use a header file which is commun between C and ASM files.

Because C is different than NASM, the layout of the header file is specific in order to work for for both compilers.

Here is the structure of the file :

; /* Comment for both C and NASM

PLACE YOUR ASM CODE HERE

%undef __TAG_TO_EXCLUDE_C_CODE_FROM_NASM__
%ifdef __TAG_TO_EXCLUDE_C_CODE_FROM_NASM__
; End of the comment */

PLACE YOUR C CODE HERE

; /*
%endif
; */


I know this file won't avoid problem because NASM Code is not "linked" to C Code, but because everything is in a single file, you can easily check for synchronisation.

Perhaps there is other way to do the same thing, but I think this code could be helpful for other OS designer. It has been tested with NASM and GCC.

Roswell

PS : It is unuseful to tell me that you can include ASM code in C file with GCC because I want to use NASM.

Re: synchronize NASM and C Code

Posted: Mon Mar 04, 2002 1:43 am
by Tim
That's pretty cool! :) I'll remember that...