Go Down

Topic: Programming  Arduino in assembly language (Read 12 times) previous topic - next topic

Old DIY Fart

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.

AlphaBeta

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

You might even be required to.

RuggedCircuits

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:
Code: [Select]
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.

Old DIY Fart

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?

RuggedCircuits

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.

Mike Mc

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.

AlphaBeta

#6
Jun 09, 2009, 01:04 am Last Edit: Jun 09, 2009, 01:07 am by AlphaBeta Reason: 1
Quote
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]

floresta

DIY

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.

Don

Old DIY Fart

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++.

Old DIY Fart

Nevermind, found it here: http://avr-studio.software.informer.com. 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).

Thanks!

RuggedCircuits

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.

Old DIY Fart

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).

westfw

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...)

retrolefty

#13
Jun 12, 2009, 10:09 am Last Edit: Jun 12, 2009, 10:10 am by retrolefty Reason: 1
That pretty much nails the Arduino's users spectrum of interests and capabilities, like herding cats around here some days.  :D

Lefty

macegr

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.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Go Up