How to program an Arduino Uno in Assembly#

2023 Feb 20

This tutorial shows you how to program an Arduino Uno R3 in AVR Assembly. The assembly program that you flash onto the Uno just blinks the built-in LED (pin 13) on and off.

Kudos to mhitza for documenting a workflow that actually works.

Assumptions#

If you don’t have the following equipment or experience, you may have a tough time completing this tutorial.

Equipment#

  • Arduino Uno R3

  • Debian-based Linux laptop that supports apt

  • USB-A to USB-B cable

Experience#

  • Proficiency in Linux CLI stuff like cd, git and ~

  • Proficiency in programming a high-level language like Python

  • Familiarity with builing binaries from source

Setup#

Create the repository#

mkdir ~/uno
touch ~/uno/blink.asm
touch ~/uno/Makefile

Install avra#

sudo apt install avra

avra (AVR Assembler) will be your assembler.

Install avrdude#

sudo apt install avrdude

avrdude (AVR Downloader Uploader) will be your tool for flashing your assembled program onto your Uno.

Create the assembly program#

Copy-paste the following code into each respective file.

~/uno/Makefile#

# Modified from https://gist.github.com/mhitza/8a4608f4dfdec20d3879
# which is copyrighted by Marius Ghita and licensed under Apache-2.0.

%.hex: %.asm
     ~/uno/avra -fI $<
     if [ -f "*.eep.hex" ]; then rm *.eep.hex; fi
     if [ -f "*.obj" ]; then rm *.obj; fi
     if [ -f "*.cof" ]; then rm *.cof; fi

all: $(patsubst %.asm,%.hex,$(wildcard *.asm))

upload: ${program}.hex
     sudo avrdude -c arduino -p m328p -P /dev/ttyACM0 -b 115200 -U flash:w:$<

.PHONY: all upload

Assemble and flash the program#

cd ~/uno
# Assumes that the Uno is connected to your Linux computer via the USB-A
# to USB-B cable and is available at /dev/ttyACM0.
make program=blink upload

You should see the built-in LED labeled L blink on for about 1 second and then off for about 1 second.

Conclusion#

The insect overlords are surely watching your (assembly) career with great interest now.