Eclipse Oxygen and NASM assembler

I had been playing about with assembler after many years of missing it and decided to try and find an IDE that works with using a C/C++ project with assembler code.

Well, I found one.

Eclipse Oxygen (may work with earlier versions too)

  1. Create a new C project. You can do this with C++ projects too if you remember to use extern “C”.

You will get a default project file like this:

2. Set up NASM for 64 bit using Project->Properties->Settings->GCC Assembler

Change ‘as’ to ‘nasm’. That is only if you already have installed NASM.

3. Set NASM to build for 64 bit.

From the screenshot showing the change from ‘as’ to ‘nasm’, now click on ‘General’ just under ‘GCC Assembler’. Now in the ‘Assembler flags’ you just add ‘-f elf64’ and click ‘Apply’. That’s the assembler setup to use the intel syntax in Eclipse.

4. Create a new file called ‘test.asm’ and copy the code below into it. If you’re in the C/C++ perspective view in eclipse you have to go round the houses to create an empty file. ie. File->New->Other->General->File and finally you are there.

EDIT: Actually, if you right click on the ‘src’ folder then you can add a blank file from there.

You now have an assembler file, empty, but it’s there.

Don’t worry at this point about things getting complicated, because Eclipse still handles the build and linking of these assembler files automatically.

Copy this code into that empty file:

In the above code I’ve declared and external function as you can see. Fortunately the underscore is still seen from C so the function name stays the same as you will see. I’m using the underscores as a note to myself that I am calling an assembler function. In future I will use a double underscore so that it doesn’t pollute other names withing the C/C++ libraries and headers.

5.  Change your C file to this:

6. Build and Run and you get the output (if you’re on 64 bit)

7. Enjoy because I am now…