Go Down

Topic: Assembly language in Arduino. (Read 2237 times) previous topic - next topic

asitmahato

Which assembler should i use to write assembly language program in arduino chip?



MGeo

If you need more than a few lines of asm, you could contemplate moving from Arduino IDE to native avr-libc.
http://www.nongnu.org/avr-libc/user-manual/assembler.html

graynomad

That inline assembler is an abomination that should have been put down at birth.

Code: [Select]
asm volatile("nop\n\t"
             "nop\n\t"
             "nop\n\t"
             "nop\n\t"
             ::);


What's with the \n\t and the quotes?

Admittedly I don't think the \t is needed (but that's from the linked page) but why need anything. Why can't you just "shell" out to ASM then come back.

Code: [Select]


// C stuff
asm volatile(nop
             nop
             nop
             nop
             );
// more C stuff


There may be a good reason for this but personally unless it's a very short piece of code I find it easier to use a separate file.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

westfw

It's a gcc things.  The "asm" statement is defined to take a string, which is more or less copied from the argument into the assembler code that (theoretically) C compilers generate in between the C source and the object files.
Strings need quotes, and (starting with gcc 4, IIRC) aren't allowed to contain actual embedded newlines.

Not my favorite gcc features :-(

I believe (saw it while reading the IDE source code) that if you have a file with the ".S" extension, the arduino IDE will include it when building the sketch (and it will get treated as a gnu assembler file.)

Note that the gnu assembler syntax is NOT the same as the Atmel-defined assembler syntax for AVRs, so you can't instantly compile any Atmel-published assembler examples.  (Gnu uses a somewhat common assembler syntax for all the different CPUs that it supports.  This has advantages and disadvantages...)

graynomad

Quote
It's a gcc thing

Yeah it's the same with LPCs when using GCC.

In the LPCxpreso IDE it's really easy to have ASM code, you just add a file to the project and start typing assembler. Have a

.global asm_test_func

in this file and

extern void asm_test_func(void);

in the C file.

I'm still new to the LPC but I gather the args are in fixed regs, I haven't tried that yet and of course there must come a time when there are too many for the regs.

______
Rob 
Rob Gray aka the GRAYnomad www.robgray.com

Go Up