I am currently creating a simple kernel and I just jumped to using C with the GCC(MinGW) compiler on windows. but the way I am using C with assembly is kind of problematic here is what I am doing :
:: First I am assembling the assembly files down to a flat binary
nasm -f bin Assembly/asm.asm -o asm.bin
:: doing the same thing for the C files
gcc -c C/c.c
objcopy -O binary -j .text c.o c.bin
:: combing the all binaries by adding them together In the desired order
COPY /B asm.bin + c.bin + asm1.asm ..... os.bin
it is kind of working, but it is also tedious working that way, first I have to break the code into segments (because I am adding each binary file on top of the other), I have to calculate the addresses manually by looking at the raw binary files, and I can't call functions from other files .
what should I do ? What is the best way to combine C and Nasm assembly on windows for OSdev ? I am guessing I should use a some sort of a linker or something.
Note that I want also to be able to call assembly functions inside c and use C functions inside assembly .
objcopy.gcc, then why not usegasfor assembly?org. If you care you can set base address using linker. Thebitsshould not produce an error, but you should already be targeting 32 bits if you want to link with C code so you don't need it. The 16 bit boot sector should be assembled separately (you don't want to link C code there).