Hi all,
I wanted to re-use some assembler code (in a .S file). After searching this forum and not finding how to do it, I came up with the following solution.
I just wonder if there's another way to avoid writing to the libraries folder.
create a folder in libraries, let's say "RoutinesASM"
inside this folder create a file "RoutinesASM.h" containing something like:
extern "C" {
void Increment_a_Number(void);
}
inside this folder create a file "RoutinesASM.S" containing the assembler routines, like:
#include <avr/io.h>
.extern a_number
.global Increment_a_Number
Increment_a_Number:
push r16
lds r16, a_number
inc r16
sts a_number, r16
pop r16
ret
the sketch must include the .h file, like:
/*
Program: Test Arduino and Assembler
Autor: [iard]
Date: 2010-06-09
*/
#include <RoutinesASM.h>
volatile int a_number;
// load the variable from RAM and not from a storage register
extern void Increment_a_Number(void);
void setup() {
Serial.begin(9600);
}
void loop() {
a_number = 5; // some initial value
Serial.print("Initial number = " );
Serial.println(a_number);
Increment_a_Number(); // call assembler routine
Serial.print("Incremented number = " );
Serial.println(a_number);
delay(1000);
}
That's it... it won't work if the .h and .S files are in the same folder as the .pde sketch.
Any suggestions?
Hi,
I think the problem lies in where the compiler looks for include files. I think you'd have to modify the compile scripts so they include the .pde folder as well.
You could try using "" instead of <> for the #include.
<> tells the compiler to search the libraries
"" tells the compiler it's part of the project
Edit:
Unfortunately the Arduino IDE doesn't really support .S files.
If you're running Arduino from source you could add the following changes. These changes and the change of <> to "" made your example compile here.
In app\src\processing\app\Sketch.java change
line 1345 from
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
to
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h") || sc.isExtension("s")) {
line 1800 from
return new String[] { "pde", "c", "cpp", "h" };
to
return new String[] { "pde", "c", "cpp", "h", "s" };
@mromani
Thanks, but the problem is that I can't find any relevant settings in "preferences.txt" and I don't know where else to look. I think the problem is related to the way Arduino IDE creates the files in the temp folder before invoking the AVR GCC compiler, because the .h file is there, but the .S is not
@qistoph
Thanks, that was my first attempt, before moving the .h and .S files to the libraries folder. Error message: undefined reference to `Increment_a_Number'
Edit: thanks again, I'll wait for the next release and until then I'll use the workaround to move the .h and .S files to libraries
by "modifying the compile scripts" I meant something along the lines of what qistoph has written (I wouldn't have been able to put toghether his solution, though)
Thanks mromani, I just hoped there was a way to modify the path in "preferences.txt" or a makefile or something. I have the Arduino IDE installed on Windows and Ubuntu (on a slow notebook), so I'm not that eager to recompile...
iard, if you're talking about recompiling the Arduino IDE;
that doesn't take really long and even isn't really complicated.
All you need is a JDK (Java Development Kit) and Apache Ant.
Compiling takes less than 2 minutes here (on a Dual Core @ 2.4 GHz), but still it wouldn't take long on any other computer.
Hmm, on my Windows machine I could do it... and maybe I will in the weekend, but how about on Ubuntu Netbook Edition running on a Asus EeePC 701 (512 MB RAM, Celeron M at 900 MHz, HDD 4GB, always running out of free disk space) :-?
I know I should stick to the AVR GCC, gavrasm and avrdude on the notebook, but the fact that I can take it anywhere with me and just plug the Arduino, start a nice and clean-looking IDE, make some changes and click on Upload seems so cool...