Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C programming question

Status
Not open for further replies.
samcheetah said:
[...] i also think that you (timtalk) should stick with C. infact ive heard (yet to confirm!) that if you use microchip's C compiler and write code for an 18 series PIC then the code generated by the C compiler will be very close to an equivalent piece of assembly code. [...]

While I believe this to be entirely plausible and in fact mostly true, it is not a strong point for skipping the assembly language learning curve and heading straight to C. Knowing assembly before tackling C, on the PIC but also on any other uC/CPU platform, can be very rewarding and help a whole lot down the line during software development, whatever language is used.

When I talk of ASM vs. C, I tend to consider the programmer's performance as a software writer, more than the resulting software's benchmarked performance...

A strong argument in favor of learning ASM first on the PIC is all the documentation, application notes and code samples provided by Microchip, which are both excellent and, as far as I know, 100% assembly language. You can apply anything described in those documents in C, provided you can read and understand ASM first.

However, like I told Tim earlier, I can understand how ASM can be totally confusing. For years I had a x86 assembly language book on my shelves, and everytime I picked it up, I had a very hard time understanding even the most basic processes and details. Learning the PIC ASM changed all that. I am now going back to that book, and suddenly everything about x86 assembly makes sense...

But before I could even learn PIC ASM, I was earning a living as a PC C/C++ software developer, with basically zero assembly language knowledge. Maybe some of us have to learn it the other way around in order for it to make some sense.
 
Joel Rainville said:
While I believe this to be entirely plausible and in fact mostly true, it is not a strong point for skipping the assembly language learning curve and heading straight to C.

My point of view is that you can't program effectively in C (or BASIC) on a PIC without at least a passing knowledge of assembler - basically because you're working at such a low level. Assembler means you HAVE to understand the hardware, in C you don't - and THAT causes many problems.

If you're not aware of what the compiler is actually producing, with regard to the hardware, it makes life very difficult. It's not uncommon to see many lines of C code being used to do something that takes only two or three lines of assembler - knowing what's going on would allow you to (often) drastically shorten the C source.
 
Joel Rainville i agree with you. but my point is that timtalk at least tried to learn ASM. and in that process he might have learned the basics of ASM which are highly recommended. one reason why he decided to go with C might be that the ASM route looks a bit longer. and thats perfectly reasonable if you are able to do everything with C (which is true!)

actually i also discourage people to learn C before learning ASM. i mean the kind of people who just dont want to learn ASM for no reason. for those kind of people i always think they should at least try to learn ASM. but timtalk has already done that. and i believe if he reads a page of ASM code and tries to understand it, he will get it.

so you get my point? 8)
 
I am able to read ASM and get a basic idea of what is going on. And I've found that by using the help file in MPLAB and looking up commands that I don't understand does sometimes clear up what they do.
 
Nigel Goodwin said:
Joel Rainville said:
While I believe this to be entirely plausible and in fact mostly true, it is not a strong point for skipping the assembly language learning curve and heading straight to C.

My point of view is that you can't program effectively in C (or BASIC) on a PIC without at least a passing knowledge of assembler - basically because you're working at such a low level. Assembler means you HAVE to understand the hardware, in C you don't - and THAT causes many problems.

Yeah, you're right. I tend to compare PIC assembly with x86 assembly, but the PIC really is a different kind of animal. Learning how the hardware works almost always means learning ASM.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top