About four years ago i stumbled upon some electronics projects on the internet and ever since i fell in love with it. So I started at basic circuits then moved to analog circuits and spent very little there then logic circuits then microcontrollers.
Each step made the abstraction of the next one very clear and easy to 'de-abstract' if i can say. So after spending some good time writing code in assembly and with the programs growing more complex and longer , the need for another transition for me from assembly to C has arisen.
The thing is that i didn't know any other programming language before learning assembly , and trying to learn embedded C from the current sources i have seems to be very hard for me as i can't 'de-abstract' the meaning of many of the language syntax. So i would like that good sources for embedded C language learning be suggested which if possible links the explanations to lower language assembly not higher ones that i already can't 'de-abstract'.

  • \$\begingroup\$ Your question seems very broad, and answers would likely be based on opinion, so it is a poor fit for this community. Please read the help center to learn how to ask good questions. Try to be more specific. What sources have you already found, and what are you finding difficult, or that they do not explain? \$\endgroup\$ – gbulmer Apr 16 '16 at 18:33
  • 2
    \$\begingroup\$ I almost made a rant as an answer. My answer: don't. To me assembly and C (however similar) are fundamentally different in thing: assembly is a set of instructions for the machine. C is a form of expression for YOU to describe your algorithm. A form of expression which is actually understandable for the machine. But that's just a personal opinion from a programmer. \$\endgroup\$ – Jan Dorniak Apr 16 '16 at 19:24
  • \$\begingroup\$ Or take a look at LLVM's Intermediate Representation language, which is sort-of in between C and assembly: en.wikipedia.org/wiki/LLVM#LLVM_Intermediate_Representation \$\endgroup\$ – Jan Dorniak Apr 16 '16 at 19:30
  • 2
    \$\begingroup\$ MostfaMahmoud - As gbulmer said, I agree this is not a good fit for EE.SE. However I'll try to help a little. I also moved from mainly assembler programming, to C programming, so I have experienced your problem. You said that you "can't 'de-abstract' the meaning of many of the language syntax" - stop trying to do that! Just accept that programming in C changes your mindset from handling every little detail (as with assembler), to describing what you want the machine to do. This is what @JanDorniak has said in a previous comment. \$\endgroup\$ – SamGibson Apr 16 '16 at 20:05
  • 1
    \$\begingroup\$ The thing people usually have trouble with in C is pointers. Coming from assembly, I'd be surprised if you have trouble with that. C is one of the most low-level languages out there. \$\endgroup\$ – Adam Haun Apr 16 '16 at 20:41

Get ahold of K&R 2nd Edition. It's a compact and dense book that covers what you need to know.

C and assembly are not that far apart, so you should make rapid progress.

| improve this answer | |
  • \$\begingroup\$ I'd highly recommend K&R 2 as well. There are more recent books and larger books, but nothing more comprehensive or lucid. \$\endgroup\$ – Dan Sheppard Apr 16 '16 at 19:24
  • \$\begingroup\$ I read about people who have difficulty learning from K&R 2, exactly because it is so dense. :-( And of course that book is stuck in a C89/90 era. So, although not aimed specifically at the assembler-to-C transition of the topic's OP, here is the canonical Stack Overflow topic on good C books, for readers who want to find alternatives: stackoverflow.com/questions/562303/… \$\endgroup\$ – SamGibson Apr 16 '16 at 20:18
  • \$\begingroup\$ As someone who has worked full-time with embedded C programming for the past 15 years, I would strongly recommend to avoid this ancient book. It is terribly outdated, it is full of errors, it contains lots of bad programming practice. The concept of proper program design is completely absent throughout the book. I'm sick and tired of re-teaching proper, modern C to people who have been damaged by this book. Also note that the book's main focus are hosted systems, mainly Unix, and not embedded systems. Instead pick something modern, that covers C99 and C11. \$\endgroup\$ – Lundin Apr 18 '16 at 7:36
  • \$\begingroup\$ @Lundin Well i think that advice is a bit late , as i have already skimmed through half the book, however , before i begun reading it i decided to take it lightly because embedded C isnt its main focus as you have mentioned earlier, but i decided to read it first just to get a general idea, then i will read Embedded C Programming and the Atmel AVR, 2e Barnett ,cox and o'cull (without leaving exercises like i'm doing with K&R). So i would really appreciate your advice and other book (instead of what i mentioned) recommendation and if i should leave K&R at all without completing it. \$\endgroup\$ – Mostfa Mahmoud Apr 21 '16 at 16:58
  • \$\begingroup\$ @MostfaMahmoud I don't really know of any beginner-friendly C books, but you should try to find one which covers at least the C99 standard. Any yeah drop K&R asap. What you should do eventually is to look into MISRA-C:2012, which is a coding standard laying out rules that lead to safe, bug-free C programs. Very suitable for embedded systems in particular - it is becoming industry de facto standard. It is not easy reading for beginners though, but knowing about it is a merit that employers will look for. \$\endgroup\$ – Lundin Apr 21 '16 at 17:52

Microchip has several free Compilers that are paired with the free MPLABX IDE (Integrated Development Environment). You can get a compiler for 8, 16 and 32-bit microcontrollers.

The difference between the free versions and the paid ones is the latter optimize the code, making the finished binary much smaller. I've seen size of the binary shrink by half.

One feature of the IDE is that you can open a disassembly window which will show you your C program followed bu the code that it generated. The following is from a PIC32 program (32-bit MIPS assembly):

enter image description here

| improve this answer | |
  • \$\begingroup\$ Is there a free program with similar feature for AVR since i'm already accustomed to its instruction set and internal architecture, or should i learn PIC assembly (which i think it wont be hard as learning a specific assembly language for the first time). \$\endgroup\$ – Mostfa Mahmoud Apr 17 '16 at 9:02
  • \$\begingroup\$ @MostfaMahmoud What processor did you write assembly code for before? I think that would be your best place to start. \$\endgroup\$ – tcrosley Apr 17 '16 at 9:07
  • \$\begingroup\$ AVR 8-bit microcontroller . \$\endgroup\$ – Mostfa Mahmoud Apr 17 '16 at 9:12
  • \$\begingroup\$ @MostfaMahmoud Sorry, I should have picked up that before when you said you were familiar with its instruction set. I'm not familiar with the native AVR development tools, but it appears Atmel has a free development suite. \$\endgroup\$ – tcrosley Apr 17 '16 at 9:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.