Which book to learn C and assembly?

Thread Starter

tuanvoi

Joined Oct 31, 2008
56
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!
 

kubeek

Joined Sep 20, 2005
5,795
Assembly for which processor and which compiler? The syntax and semantics can be VERY different with different compilers.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

Thread Starter

tuanvoi

Joined Oct 31, 2008
56
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
 

Ian Rogers

Joined Dec 12, 2012
1,136
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.
 

WBahn

Joined Mar 31, 2012
30,077
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
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.
 

kubeek

Joined Sep 20, 2005
5,795
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.
 

WBahn

Joined Mar 31, 2012
30,077
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.
 
Top