# Why avr-as doesn't work?

I've got the following program, in AVR assembly:

.DEF    WR = R16

.ORG 0

SER    WR
OUT    0x24, WR


When I call avr-as beeep.s, where beeep.s contains the previous code, I get an error message:

beeep.s: Assembler messages:
beeep.s:1: Error: unknown pseudo-op: .def'
beeep.s:5: Error: constant value required
beeep.s:5: Error: register number above 15 required
beeep.s:6: Error: constant value required


I can't find the origin of my error... What did I do wrong ?

• It looks like you are trying to compile the code written for avrasm with GNU as, which seem to have a different directives (which are not machine instructions but "pseudo-ops"). Jun 9, 2015 at 21:34
• @EugeneSh. So what instructions should I use ? Or, what Assembler ? Jun 9, 2015 at 21:35
• Take a look here. Or just use the Atmel's provide assembler. Jun 9, 2015 at 21:39
• @EugeneSh. But .dev is in this instructions set, and the same error message occurs when I replace .DEV with .dev... Jun 9, 2015 at 21:41
• Yes, but the meaning and usage are completely different. Jun 9, 2015 at 21:43

Change .DEF with .EQU:

.EQU    WR, R16

.ORG 0

SER    WR
OUT    0x24, WR
`

As described on http://www.nongnu.org/avr-libc/user-manual/assembler.html one should NOT be using avr-as directly but use avr-gcc instead.

E.g: avr-gcc -mmcu=atmega8 -x assembler-with-cpp example.s

See Note [2] of the example program on the page to see how to assign symbolic name to register.