Disadvantage of inline assembly code

Thread Starter

zulfi100

Joined Jun 7, 2012
656
Hi,
I have found following advantages and disadvantages of using inline assembly code from the web. If somebody wants to guide me in this regard, i would ighly appreciate this:

Advantage
By using ‘inline’ assembly, our instructions do not get implemented as subroutines and therefore do not take longer to process with the jumping to the subroutine and pushing and popping data off the stack.
Disadvantage
1. the disadvantage of inline assembly is that features such as high-level directives cannot be used.
2. . The disadvantage of inline assembly is that the compiled object code gets longer, but this is acceptable since we aren’t doing a lot of these nanosecond delays.
If there is something more plz guide me.

Zulfi.
 

MrChips

Joined Oct 2, 2009
30,806
You have to ask and answer the following questions:

1) Why do you want to use inline assembler?

2) Where would you use inline assembler?

3) How do you implement inline assembler?

4) When would you NOT use inline assembler?
 

Thread Starter

zulfi100

Joined Jun 7, 2012
656
Hi,
Thanks for this question. It would increase my knowledge regarding this topic.
1) Why do you want to use inline assembler?

we would use in-line assembly language when a high level language does not support some features related to system programming or (according to book) when we increase in speed or when we want to use actual bytes of machine code.

2) Where would you use inline assembler?
In a high level language

3) How do you implement inline assembler?
Using special directives for example #pragma in case of 'c' language

4) When would you NOT use inline assembler?
When we dont need to perform system programming task for example when we are doing data base programming.

These are good questions. Kindly tell me your response in this regard.

Zulfi.
 

MrChips

Joined Oct 2, 2009
30,806
1) Why do you want to use inline assembler?
Normally one will chose to program entirely in ASM or entirely in C. Hence inline assembly is not a necessity.
2) Where would you use inline assembler?
You may want to switch to ASM in order to optimize the code for efficiency or to take advantage of special processor operations such as DSP functions, MAC (multiply and accumulate) if it is not implemented by the compiler.

3) How do you implement inline assembler?
The way inline assembler is implemented differs with each compiler.
The easiest way is with block code delimited by asm{ } (as in CodeWarrior).
Some compilers make it tedious by requiring asm( "... ") on each line.
Other compilers (IAR) make it easy to call functions coded in asm.

4) When would you NOT use inline assembler?
When the compiler has code optimization and does a pretty good job of generating optimized code.
 

MrChips

Joined Oct 2, 2009
30,806
The only disadvantage I can think of, is months later, you or some other programmer will not be able to understand what you did.
 
inline programming is best for starters and onwards..when we start to systemize/optimize/clean up assembly language, we opt to omit inline programming to open way on structures easy readable by others, this is by the time we go advance on it..

when i was a starter on this, my code was soooo long on one page, no one can understand it.. months later i learned re structuring it, in those days my classmates started to look through my codes and started appreciating it, because they understood it..

--hope this helps..cheers!
 

WBahn

Joined Mar 31, 2012
30,057
With optimizing compilers getting so good it boarders on sorcery, the need for inline assembly code is getting less and less. Still, most compilers only implement a portion of the instructions available on any given processor (for big processors, not so much embedded-type processors), so someone that knows the instruction set well is in a position to identify when a snippet of assembly code using specific instructions might give a big performance boost.

But one huge disadvantage is that you give up portability. Your code will now only compile and run on the subset of processors that support the assembly code you used.
 
Top