This is NOT a tutorial on C or asm, you will already need to have existing knowledge of them and how to install them.

INTRODUCTION

There are many reasons why you would want to use asm with C, optimization and code-control are usually the main reasons.
The way this will work, is making object files from all source files, and then proceeding to compile them using gcc altogether at the end.

SETTING UP YOUR ENVIROMENT

If you&#039;re using linux, you can skip this part, this part is only needed by windows users.

In order to quickly compile/assemble files in the command prompt, without having to type like C:\Mingw\bin\gcc -c file.c -o file
you need to set up your %PATH%, the best way to do this is:
1) Right click "My Computer"
2) Click properties
3) Click Advanced/Advanced system settings
4) Click Enviroment Variables
5) If you have Admin access edit the system PATH variable, and ADD the full path for for gcc, nasm and masm32; followed by ";".
If you do not, make/edit a PATH variable in your User variables section.

An example of what to add to your PATH variable:
C:\MinGW\bin;C:\nasm;C:\Masm32\bin;

CREATING OBJECT FILES

GCC:
CODE :

gcc -s -O3 -c <file>.c -o <file>.o

Note: While I&#039;m using the -s and -O3 switches for gcc, you only need to use the -c switch

NASM(linux):
CODE :

nasm -felf <file>.asm -o <file>.o

NASM(win32):
CODE :

nasm -fwin32 --prefix _ <file>.asm -o <file>.o

Note: The prefix is there because windows object files apparently have a _ before each function name.

MASM32(win32)
CODE :

ml /Fo <file>.o /coff /c <file>.asm

Note: In your masm32 source files, do NOT include libs, only the inc files.
You will also need to add "end" at the end of the source files.

EXAMPLE PROGRAM

example1_c.c:
CODE :

#include <stdio.h>

void asmfunction(void);

int main(void)
{
asmfunction();
}

example1_nasm.asm(nasm):
CODE :

[bits 32]

extern printf
global asmfunction

section .data

printf_s db "Hello World",10,0

section .text

asmfunction:
push printf_s
call printf
add esp,4
ret

example1_masm32.asm(masm32):
CODE :

.386
.model flat, c
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\msvcrt.inc
include \masm32\include\masm32.inc