Disadvantage of inline assembly code

Discussion in 'Homework Help' started by zulfi100, Jun 22, 2013.

  1. zulfi100

    Thread Starter Member

    Jun 7, 2012
    320
    0
    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
    Disadvantage
    If there is something more plz guide me.

    Zulfi.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    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?
     
    absf likes this.
  3. zulfi100

    Thread Starter Member

    Jun 7, 2012
    320
    0
    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.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    Normally one will chose to program entirely in ASM or entirely in C. Hence inline assembly is not a necessity.
    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.

    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.

    When the compiler has code optimization and does a pretty good job of generating optimized code.
     
    absf likes this.
  5. zulfi100

    Thread Starter Member

    Jun 7, 2012
    320
    0
    Hi,
    Thanks my friend for your update on this. But plz tell me :
    Zulfi.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    The only disadvantage I can think of, is months later, you or some other programmer will not be able to understand what you did.
     
  7. circuitfella11

    Member

    May 10, 2013
    56
    5
    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!
     
  8. WBahn

    Moderator

    Mar 31, 2012
    17,757
    4,800
    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.
     
  9. zulfi100

    Thread Starter Member

    Jun 7, 2012
    320
    0
    Hi,
    Thanks for your response. I forgot to think about the portability and understandability issues.

    Zulfi.
     
Loading...