The move from Assembly Language to C

Discussion in 'Programmer's Corner' started by ke5nnt, Dec 30, 2010.

  1. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    I have a pretty generic understanding of Assembly at this point, but I'd like to maybe migrate over to C since it seems to be the standard programming language for PIC Micros. I learned assembly with a book called Know it All PIC Microcontrollers from Newnes publishing, which was a great book and helped tremendously; and also from members at AAC.

    Now I'm trying to decide on a good book for getting started with C that is for beginners (no prior knowledge of C required). An search of "C Programming for PIC Microcontrollers" yeilds a number of results. Anyone have any good suggestions?

  2. Tahmid

    Active Member

    Jul 2, 2008
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    You should not have too many problems moving over. It is where I got my start. Actually I got my start in machine code and when the PET got an assembler, it was a major improvement to coding.

    I like this site. They have some good lessons and it is free.
  4. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    Code ( (Unknown Language)):
    2. example code (not really a program)
    4. while (1)
    5. { this is point A
    6.    program goes here, etc
    7.     {
    8.      branch}
    9. }point B
    Can someone help me understand the While (1) loop? Does the loop begin at point A and end at point B, and then return to start again at point A? Am I to understand that the purpose of the (1) is that while the condition is other than "1" the loop will repeat, which is essentially forever since the condition can never be "1"? I'm sorry for such a stupid question but I'm new to C.
  5. nerdegutta


    Dec 15, 2009

    I use the:

    Code ( (Unknown Language)):
    2. while (1)
    3. {
    4. some stuff
    5. }
    whenever I need a endless-loop. It repeats inside the brackets until program it terminated by a reset, power off, or a break statement inside the while-loop.

    I have this kind of loop in a small LED chaser program. Inside the loop, it checks if a bit is set high. If its high, the program exits the loop, perform a procedure on flashing some LEDs, and returns to the loop. Checking for next bit to be set high.

    Read this

    It repeats since the condition is true. 1 is equal to 1.
  6. myforwik

    New Member

    Feb 15, 2010
    The loop begins and ends at the outer { } brackets. while (statement) { } means the program will execute the commands between the { } , then check if the statement is true, then execute them again and so on. So the things inbetween { } get execute while the statement is true.

    The only way the loop can exit is by a break; statement, which causes execution to jump to the } bracket.
  7. etuzuner


    Mar 21, 2009

    You can use both languages in CCS C compiler. Did you think about it?
  8. AlexR

    Well-Known Member

    Jan 16, 2008
    You can use in-line assembler in most (all?) PIC C compilers but unless you have some pressing need (such as critical timing requirements) its best to avoid the practice. The whole point of writing in C is to produce code that is easy to read and maintain, the last thing you need is blocks of assembler mixed in with the C code obscuring its meaning and making it hard to understand.