Which book to learn C and assembly?

Discussion in 'Embedded Systems and Microcontrollers' started by tuanvoi, Mar 15, 2013.

  1. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    Hello,
    I'm a new learner of using C and assembly together in 1 source code. Could you please tell me which book is good for beginner like me? Thank you!
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Assembly for which processor and which compiler? The syntax and semantics can be VERY different with different compilers.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    One would hope you already know C and the assembly language for your target device.

    To learn how to combine them look at the manual for the compiler you use.

    If you need to learn either C or the assembler, do those first.
     
  4. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    Hello,
    I just want to learn a general idea of how to combine C and assembly in the source code. My target is to learn and use PICs from Microchip. Thanks again
     
  5. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    With the free compilers from Microchip You can include asm very easily... They have an asm(); function.... Passing variables is slightly more complicated but it is well documented.
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    I would still heed ErnieM's recommendation. You don't need to learn either too deeply, but do at least get reasonably acquainted with both separately before you try to hold a shotgun wedding. If nothing else, it will make it so that, when things invariably go wonky, you can more quickly conclude whether to blame the C, the assembly, or the marriage.
     
  7. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I personally think that using inline assembly in C code is not a very good idea, except for NOPs to get some critical static timing.
    Much better way when you really need to do something in assembler is to use a separate assembler file with its own headers etc. to do the critical function, and call if from the C code.
    This way you have clear separation between the C mess and the asm mess, and once you verify the assembler works the way you want it you can forget about the details. But if you mix a lot of assembler inside a C code, things could easily get very convoluted and strange things will start to happen.
     
  8. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    I tend to agree. Unless you have critical timing needs that can't be met with anything other than inline code, separate the two. I would tend to recommend doing it all in C (if possible) first, without worrying about performance, and then turn one of the parts you want to eventually make assembly into a function call of a C functions, and finally write and call an assembly versions of that functions instead. This way, you can stop this process of writing assembly functions as soon as your code achieves the performance needed.
     
Loading...