I have an ATMEL C project (ATmega328) in ATMEL Studio 7 and need to mix in some assembly code.
I don't want to use the C inline assembly asm()
directive because I want to keep it separate as a pure assembly file.
I want to include .asm
to my project, but here is the thing.
For a C project it allows me to create .s
or .S
files. These are apparently using a different assembler than the .asm
files because in .s
files commands like .inc
or .equ
is not recognized.
However, if I rename the .s
to .asm
, ATMEL Studio won't invoke the assembler (as for a pure assembly project). I guess I could solve this with the Pre-Build event to manually invoke the right assembler for the .asm
files.
I can stick with .s
(although I prefer the .asm) file if there was a way to include all the I/O register definitions. #include <avr/io>
itself doesn't generate an error but it doesn't define anything either.
#include <avr/io.h>
.global ReadFlux
ReadFlux:
ldi r24,'#'
out TCNT0,r24
in r24,TCNT0
ret
...so TCNT0 is not known and generates an error.
I need to get the assembly version of it; m328def.inc
but that one can't be found and also use .equ
, not recognized by the .s
assembler.
What is the proper way to setup the .s
so I don't have to manually define every single IO register?
or (preferably, use the .asm
instead).
EDIT
So there are two assemblers; avrasm2.exe and avr-gcc.exe with the assembler-with-cpp
directive. In a pure Assembly project it seems like avrasm2.exe is used and in a C/C++ project the GNU assember is used. These 2 flawors are not working in the same way, hence the confusion.
For example with avrasm2.exe I can write like this:
out DDRB,r16
but with avr-gcc.exe I have to write it like this:
out _SFR_IO_ADDR(DDRB),r16
I think the mystery has been solved for now, but I still prefere the avrasm2.exe instead.