Programming Arduino with Assembly

23 Oct 2016

Arduino is typically programmed with Arduino IDE with a set of C/C++ functions.
The canonical blink sketch which turns a led on/off every 1 second looks like:

void setup() {
pinMode(13, OUTPUT); // initialize digital pin 13 as an output
}
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

pinMode, digitalWrite and delay functions are defined by the Arduino
standard library. For the most part this works pretty well, and there are plenty
of libraries and example sketches.

For the sake of getting close to the metal, let’s write the above sketch in
assembly instead. Before we do that we need to install couple depedencies. Assuming you’re on OSX and you have brew install you’ll need to do: