C vs. Assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
chris

C vs. Assembly

Post 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?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:C vs. Assembly

Post 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.
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:C vs. Assembly

Post 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' ...
Post Reply