Society of Robots - Robot Forum

Software => Software => Topic started by: vipulan12 on May 20, 2014, 02:58:55 PM

Title: assembler vs another language
Post by: vipulan12 on May 20, 2014, 02:58:55 PM
When programming a micro controller you could assemble or C, is their any advantage between the two in terms of applications?

asseble takes up less space but is their any other advantages over C?

Title: Re: assembler vs another language
Post by: jwatte on May 21, 2014, 09:25:41 AM
Assembler doesn't take up less space except in certain cases. The main benefit is that you have full control over the hardware.

There are cases, such as certain watchdog, windowed-write, or interrupt-routine applications, where the number of cycles must be controlled very exactly, and with assembler, you can do exactly that.

There are also cases where specific instructions have no equivalent in C, and you must use assembler for that reason. Typically, you implement a C-style function interface in assembler, and call that function from C to get access to the special instruction.

Use assembler when you cannot get what you want in C. Otherwise, use C.
Title: Re: assembler vs another language
Post by: waltr on May 21, 2014, 11:42:18 AM
Quote
Assembler doesn't take up less space except in certain cases.
This is highly compiler dependent. For example the Free versions of the compilers for MicroChip PICs do not optimize so the code produced is 3 to 4 times larger than if you buy the top end compiler and use full optimization. This also means well written assembler code will be about the size size or smaller than fully optimized C code.

I use C code when code size or execution speed is not as important (using free non-optimizing compiler) else I use Assembler.
Title: Re: assembler vs another language
Post by: jwatte on May 21, 2014, 04:22:40 PM
I assume that you use competent tools for the application you are targeting.
If you choose to shoot yourself in the foot for one reason or another (cost, prejudice, poor vendor choice, ...) then of course you will be limping.