Page 1 of 1

C vs. Assembly

Posted: Thu Dec 18, 2003 7:24 pm
by chris
I see that in some kernels people use assembly to do things such as change certain ISR's for different interrupts; and others use C. Is there any significant advantage from one to the other?

Re:C vs. Assembly

Posted: Fri Dec 19, 2003 2:29 am
by Solar
Assembly allows you more fine-grained control of what you do. It also allows you to do certain things at all, which is why there's always some amount of Assembly involved in OS development.

C, on the other hand, is known better by most people, which makes it easier to track down bugs or contribute some code.

Assembly is usually very dependent on the Assembler software employed, whereas well-written C code can be compiled by most compilers unchanged.

Many people claim that Assembly is more efficient. I'd rather put it this way: Assembly has the potential of being more efficient than compiled C, if you know exactly what you're doing. That was pretty easy with, say, a MC68000 or a i80286. However, CPUs have grown more and more complex, with superscalar pipelined architectures that result in hand-written Assembly having the potential of being much worse than compiled C.

Re:C vs. Assembly

Posted: Fri Dec 19, 2003 5:08 am
by Pype.Clicker
and for ISRs, assembly is mandatory, as your C compiler doesn't know what's the difference between a 'return' instruction and an 'interrupt return' ...