Are there any situations where programming an embedded processor "requires" at least some assembly code? How about for AVR, MSP430, 68HC11, 8051(Atmel)? Can these 4 microcontrollers be programmed fully in C without touching assembly (even interrupts and etc.)?
mixing C and assembly
Started by ●April 22, 2008
Reply by ●April 22, 20082008-04-22
Lax wrote:> How about for AVR, MSP430, 68HC11, 8051(Atmel)? > Can these 4 microcontrollers be programmed fully in C without touching > assembly (even interrupts and etc.)?At least for AVR one can write pretty much everything using gcc and avr-libc. However, while writing "cli();" in your C program is not technically "touching assembly", it is not much different from including the cli instruction as inline assembly. It is more convenient, but still very much target dependent. -- Pertti
Reply by ●April 22, 20082008-04-22
Lax pisze:> How about for AVR, MSP430, 68HC11, 8051(Atmel)? > Can these 4 microcontrollers be programmed fully in C without touching > assembly (even interrupts and etc.)?IMO, generally it is possible, but sometimes C compiler doesn't optimalize code such good as you want. In this case you can write it in assembly language or change your approach to the problem. -- Piotr Piwko http://www.embedded-engineering.pl/
Reply by ●April 22, 20082008-04-22
Lax wrote:> Are there any situations where programming an embedded processor > "requires" at least some assembly code? > > How about for AVR, MSP430, 68HC11, 8051(Atmel)? > Can these 4 microcontrollers be programmed fully in C without touching > assembly (even interrupts and etc.)?You have to resort to assembly in the two special cases: 1. The system level work like switching the contexts of the tasks, C startup code, etc. 2. The parts of code where the performance is very critical. Other then that, everything can be done in C. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●April 22, 20082008-04-22
I think that it should be possible, although as it has been said, C compiler may not optimize your code properly, and you may have some lost of performance. You may try the asm directive of C as a solution to avoid writing a whole file in assembly code. Good Luck!> >Are there any situations where programming an embedded processor >"requires" at least some assembly code? > >How about for AVR, MSP430, 68HC11, 8051(Atmel)? >Can these 4 microcontrollers be programmed fully in C without touching >assembly (even interrupts and etc.)? >
Reply by ●April 22, 20082008-04-22
On 2008-04-22, Lax <Lax.Clarke@gmail.com> wrote:> Are there any situations where programming an embedded > processor "requires" at least some assembly code?Usually.> How about for AVR, MSP430, 68HC11, 8051(Atmel)?Yes.> Can these 4 microcontrollers be programmed fully in C without > touching assembly (even interrupts and etc.)?Sometimes. It depends on the toolchain and on the job to be done. Most toolchains provide C extensions to do things like interrupts and access special hardware features. If those extensions are sufficient for what you need to do, then you don't need to write assembly code. If they aren't, then you do. -- Grant Edwards grante Yow! ... or were you at driving the PONTIAC that visi.com HONKED at me in MIAMI last Tuesday?
Reply by ●April 22, 20082008-04-22
"Lax" <Lax.Clarke@gmail.com> wrote in message news:2defcf6d-7dab-4699-9ce1-d433240398e4@m36g2000hse.googlegroups.com...> Are there any situations where programming an embedded processor > "requires" at least some assembly code?In every case where I've worked an embedded processor directly, I've had to at least initialize the environment so it could run C. Basically, setup the stack, clear RAM and jump to _main. In cases where there's an OS on it already, and that has an applications hook, then it could have been done with only C. In some cases, however, it's been expedient to use some assembler.> How about for AVR, MSP430, 68HC11, 8051(Atmel)? > Can these 4 microcontrollers be programmed fully in C without touching > assembly (even interrupts and etc.)?I have no experience with the first two. For the last two, without an OS, yes. With an OS, for the 68HC11 I did for expediency, but could have avoided it, but for the 8051 I had to do some assembly. Perhaps selection of a different OS or development package would have made it possible to avoid assembler. - Bill
Reply by ●April 22, 20082008-04-22
On Apr 22, 9:51 am, "Bill Leary" <Bill_Le...@msn.com> wrote:> "Lax" <Lax.Cla...@gmail.com> wrote in message > > news:2defcf6d-7dab-4699-9ce1-d433240398e4@m36g2000hse.googlegroups.com... > > > Are there any situations where programming an embedded processor > > "requires" at least some assembly code? > > In every case where I've worked an embedded processor directly, I've had to > at least initialize the environment so it could run C. Basically, setup the > stack, clear RAM and jump to _main.There are always assembly involved somewhere, but you don't have to write them. Why are you re-inventing run-time libraries?> > In cases where there's an OS on it already, and that has an applications > hook, then it could have been done with only C. In some cases, however, > it's been expedient to use some assembler. > > > How about for AVR, MSP430, 68HC11, 8051(Atmel)? > > Can these 4 microcontrollers be programmed fully in C without touching > > assembly (even interrupts and etc.)?Yes for AVR, you can interrupt, sleep, powerdown and change clock speeds in C. The only assembly I have used is to load flash codes into data space, for which there is no C equivalent.> > I have no experience with the first two. For the last two, without an OS, > yes. With an OS, for the 68HC11 I did for expediency, but could have > avoided it, but for the 8051 I had to do some assembly. Perhaps selection > of a different OS or development package would have made it possible to > avoid assembler. > > - Bill
Reply by ●April 22, 20082008-04-22
Vladimir Vassilevsky wrote:> You have to resort to assembly in the two special cases: > > 1. The system level work like switching the contexts of the tasks, C > startup code, etc. > > 2. The parts of code where the performance is very critical. > > Other then that, everything can be done in C.Vladimir, In your second point I would qualify it to parts of code requiring exact timing on anything that we have released recently that seems to be the only limitation. Regards, -- Walter Banks Byte Craft Limited Tel. (519) 888-6911 http://www.bytecraft.com walter@bytecraft.com
Reply by ●April 22, 20082008-04-22
On 2008-04-22, Bill Leary <Bill_Leary@msn.com> wrote:> "Lax" <Lax.Clarke@gmail.com> wrote in message > news:2defcf6d-7dab-4699-9ce1-d433240398e4@m36g2000hse.googlegroups.com... >> Are there any situations where programming an embedded processor >> "requires" at least some assembly code? > > In every case where I've worked an embedded processor directly, I've had to > at least initialize the environment so it could run C. Basically, setup the > stack, clear RAM and jump to _main.For processors without an external bus (IOW they have a fixed memory map), many toolchains will provide startup code that does all that. That's certainly true for GCC on the Atmel AVR and TI MSP430: tell the compiler which part you're using, and you don't have to write a lick of startup code. -- Grant Edwards grante Yow! Did something bad at happen or am I in a visi.com drive-in movie??