Programming  Arduino in assembly language

Hi; newbie here, so hopefully this is the right forum in which to ask this question.

I'm thinking about starting to play with the Arduino. From what I've read, the "native" language (or language of choice) is C/C++. But what if I want to use the MPU's assembly language instead? I didn't find anything on this site about this (haven't searched the forums completely, but so far no answers to my questions).

Notice I said "want to use assembly language". It's actually my preference when programming small processors like these. (My experience so far has been with the former Ubicom SX-28 micros.)

Does the development kit one gets with the Arduino packages support assembly language? or does one need to get extra software to do this?

Thanks for any help here.

If you want to program low-level, I think you will be much happier using AVR Studio.

You might even be required to.

It's certainly possible to program the AVR in assembly language, but you'll have to do a little extra legwork. The compiler used by the development kit is AVR-GCC, which supports assembly language as an input, but this isn't directly an option from the GUI.

If you want to use an Arduino with its entire GUI infrastructure, libraries, etc. then it's best to use C/C++. If you just want to use it as a microcontroller board, you can achieve the same results using AVR-GCC and AVRDUDE for sending your results to your board, and bypass the GUI altogether. It's easier to program in assembly that way.

You can also mix C and assembly using the "asm" pseudo-function. By using the "naked" attribute for functions, you can write your entire program in assembly code, but from within a C file so that the compiler takes care of all the labels, section directives, etc. For example:

void somefunction(void) __attribute__((naked))
  asm volatile ("

 ; your assembly code here


Final word of advice: it's really not worth it. I understand the desire to be as close to the machine as possible, but the AVR architecture makes hand-assembly not that much less efficient than C-language-generated code. Unlike other processors (mostly from the past) where a 10-to-1 improvement is fully expected when comparing higher-level languages to assembly, in my experiences this just no longer holds. The underlying architecture is so C-friendly (lots of registers, orthogonal instructions) that the compiler-generated code is really good.

Rugged: Thanks for the quick reply. And while I don't doubt that C makes things easier, I still prefer down-to-the-bits assembly language for these kinds of projects, primarily for personal reasons. Besides, while I know C, I don't know C++, and really have no desire to learn it (not planning on entering the programming job market any time soon). All that class stuff, etc., gives me a headache.

So it sounds like AVR-GCC is what a guy would want to use. Is there any documentation on this available before buying the product?

AVR-GCC is free and fully documented here. This is the home page for the C library that supports the AVR's (called AVR-LIBC), but it also describes how to get and install the AVR-GCC toolset.

The whole purpose of the Arduino language is that it is C with abstractions to make it nice and easy to program. You don't need to learn C++ at all.

However, if you are more comfortable in ASM then you would be better of with AVR Studio.

You don't need to learn C++ at all.

Actually, I think you will use/learn c++ sooner or later with the Arduino. And honestly, I can't imagine why not learning c++ would be a good thing? 8-)

Serial.println("this is c++");

[edit]AVR Studio 4[/edit]


I have been doing some tinkering in assembly language using two of the 'duino boards. If you haven't purchased a board yet then make sure you get one with an ICSP header - it makes things a lot easier. A real Arduino should be ok and I know that the Modern Device BBB and Lady Ada's Boarduino are suitable.

All you need to do is download the free AVR Studio 4 IDE and make or buy a programmer. The AVRISPmkII programmer was available in the US from Digikey for $34 the last time I checked.


Thanks for that. So where, exactly, do I get AVR Studio? I searched for that string on this site, and all I got were lots of forum messages.

And is there any documentation I can look at on it? Why is it so difficult to find this stuff? Everything I read on both the download and reference pages implies that the software supports only C/C++.

Nevermind, found it here: Didn’t realize it was “off-site”.

So if you’ll pardon this n00b, some questions: Arduino doesn’t actually make the microprocessors, right? These come from Atmel? And what does “AVR” stand for, anyhow? Seems to designate this line of uPs.

I would still like to peruse some written documentation on this before downloading (I’m still on dialup here).


Atmel makes the processors, and "AVR" is the name for their brand of 8-bit microcontrollers. You can download AVR Studio and lots of documentation on their devices from their site.

Many of their datasheets run into the megabytes. Dialup is not going to like that.

The reason you're not finding anything about it on this site is because Arduino tries to make it as easy as possible for beginners to get started with microcontrollers, which means sweeping a lot of information and low-level details under the rug. For example, people are often surprised that the AVR has no notion of "pin 13" but instead breaks the I/O pins up into multiple ports of 8 pins each. "Pin 13" is a higher-level construct layered on top of that.

Thanks again.

I should explain my motivation here: while I do prefer the more primitive approach of assembly language for programming, and don't really appreciate or need the "hand-holding" nature of C (or Basic!) programming, I do like the way that Arduino packages the hardware into a neat little bundle. No need to supply my own oscillator crystals, voltage regulators, etc., and the board has easy-to-use connections.

I'll download some of those PDFs later (start download, come back in an hour or two).

It's fascinating to hear you say that, since I've heard other people say exactly the opposite ("I really like the way the Arduino environment simplifies software development, but the hardware is an overpriced piece of fluff that I could easily make myself.")

(To my thinking, both comments emphasize the "correct" placement of Arduino. It appeals to people who COULD make their own hardware. It appeals to people who COULD write their software from the ground up in raw assembler. It appeals to people who COULD do both. And of course it appeals to people who aren't particularly interested in doing either one, but still want to achieve a result best implemented with a microcontroller...)

That pretty much nails the Arduino's users spectrum of interests and capabilities, like herding cats around here some days. :D


Right. Some of us are saying "Oh wow, here's this tiny cheap device that I can program like a computer to do anything" and others are saying "Just this once I'm going to splurge on a huge development board with all sorts of features and I don't have to solder anything or keep a 496 page datasheet handy."

I got into Arduino from the hardware side, initially resisted the idea of paying $30 when I could knock together other uC circuits for $10.

I appreciate how easy the development environment is to use, too. But here's the main reason I use Arduinos now: whatever I build is accessible to anyone. It's easier to share ideas when there's a common platform. If someone wants to try out a microcontroller application I've put together, they don't have to pick up a soldering iron right away.

I agree. Also, one reason I stay with the Deumilanove, rather than moving voer to the Mega, is that the chip is PDIP and therefore I can program something, prototype it then pop the chip out and make my own custom PCB with the chip.

I don't personally want to learn C++ or all about Port Manipulation, etc. unless it is absolutely necesary and the Arduino environment enables me to do that with relative ease.

I don't personally want to learn C++

I am willing to bet quite a lot on the fact that you already know C++. :)

I know a little bit yes. I like C but C++ is a bit confusing to me.

The officiel Arduino IDE does not support gcc assembler files. These files have the file extension .S. You can only use inline assembler with the official IDE.

I modified the IDE in a way that the assembly language can be used for sketches. Have a look at the LumiNet thread in this forum and you will find my patches or the whole modified IDE for download. For example, I implemented/ported a very fast software serial lib in assembly language for my ATtiny-based Arduino-compatible boards. And because assembly language, C, and C++ use the same (gcc) compiler, you can call routines from one language in another one.

AVR Studio is something different, they use the official Atmel assembly language. This is not gnu, not open source... So I guess for the community, gnu gcc assembly language would be better suited. But it is your choice... I would love to see an Arduino assembly language group.

I too would be interested in having the ability to learn and utilize some assembly language code in sketches, using the Arduino IDE to help with some abstractions and all the gory low level stuff that assembly coding usually carries.