AVR Assembly programming on Mac OS X

I am writing this blog entry because it took me quite a lot of time to figure out how to write AVR assembly code and assemble it on OS X. CrossPack is great to get started writing C code for AVR chips and possible use some inline assembly. CrossPack install the AVR GNU assembler avr-as described here. The assembly files typically end with .S. You can invoke it through gcc with e.g.

avr-gcc -Wall -Os -DF_CPU=8000000 -mmcu=attiny13 -x assembler-with-cpp -c ledflash.S

This will assemble the file ledflash.S for the AVR microcontroller unit (MCU) ATtiny13. The problem with this assembler is that it does not use the same directives as the the official ATMEL  assembler. Most example code and tutorials you can find online is written according to the ATMEL assembler.

Fortunatly if you look around you can find the open source avra assembler. A problem when first googling is that an older assembler tavrasm will more likely pop up first in your search. Ignore this one. It does not seem to be maintained.

Avra is newer and is very  easy to compile yourself. There are no dependencies. You just have to give a list of files to gcc or clang to compile it. To check that everything has been assembled correctly you can use the vAVRdiasm to diassemble the .hex file and see that you get back something that looks like what you put in 😉

There is also a TextMate bundle avr-assembly which you can install which makes it possible to have syntax highlight for your AVR assemble programming.

As a final note, be aware that you have to fiddle a little bit with all of this software. A lot of stuff did not work exactly as the manual said. It is usually just very minor adjustments to make it work. E.g. the TextMate bundle instructions gave the wrong path to bundles for TextMate2.

Leave a comment