Assembly language function in IDE

Is there a way to use the Arduino IDE facility to insert an assembly language function into the Sketch? I have a Due product and I want to buy an Assembler for Atmel or Arm microprocessors so I am not slowed down by Object Oriented Program bloat. I have used assembly language for Java bytecodes in a stack based situation and assembly language for other processors and it is the fastest way to get pins to read and write.

Yes. The compiler is GCC, so you use the GCC inline assembler syntax.

A good quick intro is here: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html - note, this is (I think) written with x86 in mind, so the op codes and registers will be wrong, but the syntax will be the same.

Assembly language may be the fastest way to read and write pins but don't bet on it. You can access the Arduino ports directly to read and write individual bits and not use the normal read and write functions. I would be interested to see a timing comparison between assembly and direct port access.

See http://www.arduino.cc/en/Reference/PortManipulation for a discussion of the reasons why you would/would not use direct port manipulation. The arguments against it would be magnified even more by the use of assembly language but, of course, there may be cases where you have no choice. What sort of applications have you got in mind ?

UKHeliBob asked, "What sort of applications have you got in mind ?"

My present project is a musical drumset using magnetic drumhead drivers. Each drumhead has magnets on it and a coil of wire is near the magnet. The audio signals are less than 1000 hz and I use light beams to detect the phase of the drumhead motion. The Arduino Due sets analog voltages on capacitors so the VCO voltage controlled oscillators drive the coils using powerful amplifiers.

The assembly language is not needed for those slow functions, but future work might need high speed assembly language programs to respond to coordinate the phase of the coil current with the phase of the drumhead position.

I know of three ways to use assembly in my sketches.

1) Use in-line assembly directive. It works, but... Ugh. Writing very much assembly in that syntax is... just Ugh. 2) Drop a .S file in the IDE's working directory. It will assemble and link it in. The problem is the working directory changes every time I exit out of the IDE. I have to track down the new folder and copy the file in there by hand. I haven't figured out how to do this automatically yet. But, it works. 3) Do the entire program in assembly and use a shell script or batch file to assemble it and copy to the Arduino. I know this doesn't answer your question about interfacing with the IDE, but sometimes it's the easier way.

@TanHadron

For finding the Hex folder I have this bat file (lost original source), which generates a txt file which opens in Notepad++
In the textfile I can see which .hex files are present and select the whole or partial path

REM FindHex.bat for Arduino
REM Locate the current HEX files from
REM use of the Arduino 1.0 compiler
SET HEX=""
ECHO OFF
CLS
C:
CD \
dir %temp%\*.hex /s  /b >HexRhere.txt
ECHO.
ECHO.
SET /P HEX= <HexRhere.txt
Explorer %HEX%
Explorer \HexRhere.txt

The problem is the working directory changes every time I exit out of the IDE. I have to track down the new folder and copy the file in there by hand. I haven't figured out how to do this automatically yet.

Add to your preferences.txt fro example:

build.path=c:\YourCode\Arduino\YourBuild

Now all your builds will happen in c:\YourCode\Arduino\YourBuild...

Thanks, pito. I figured there was probably a way to do that, but hadn't gotten around to tracking it down.