• 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.

Learning C or Assembler ?!

Status
Not open for further replies.

csaba911

Member
I'm using assembler for the last 8-10 months to create programs for PIC's, most of the time is simple application, I have some difficulty with the MATH. Floating point calculation,16X16, 32/16 math is seams to be impossible. Readed some .asm created by others, cant follow their logic, is C better for math. How difficult is to learn C, looks like more complicated to me !
Any specific C compiler better than the other ?
Thanks for any input on this.
:idea:
STEVE
 

Nigel Goodwin

Super Moderator
Most Helpful Member
As I'm sure you already know, a PIC (as with any processor) runs machine code - assembler translates directly to machine code (although if you really want to, you could do manual translation).

A C compiler takes a high level language and writes the assembler for you, so you have less control over your code than writing in assembler. The advantages of this are that it writes complicated code without you having to know the details of it, but you can always write the code in assembler if you wish.

For maths problems you need to write a set of maths subroutines (if you look on the PICLIST there are various routines available) then simply feed it the data and call the routine - which is all that a high level compiler does anyway.

If you don't already know C, and have a reasonable working knowledge of PIC assembler, it seems a backward step moving to C (or any high level language).
 
I programmed in assembly for the longest time, then I got off my but and started to program in C. It's freekn' awsome. A whole new world opens up. I would get a book the focus is to teach C for microcontrollers.

as far as 32/16. There is an easy way to divide and multiply in assembly. You have to think in Binary though. A shift right will divide by 2. a shift left will multiply by 2.

32= 0010 0000

shift 4 times to divide by 2. 1st shift = /2 2nd shift =/4 3rd shift =/8 4th shift =/16

result=0000 0010 =2 = 32/16

hope this helps
 

bmcculla

New Member
I'd recommend learning C.

Math is much easier. If the Compiler you use has a floating point library Floating pt math works the same as integer math- same with 32 and 16 bit math. Careful with floating point math on an 8 bit processor its really really slow and takes up a lot of code space.

C is also very flexible. If you need to port your code to another processor its a much easier job than translating assembler. Most of the code will work without any changes.

C makes it much easier to manage large programs. You can implement data structures to logicaly organise your code. Arrays are easy to use. And just the fact that there are fewer lines of code makes it easier.

Most compilers allow you to use assembly code segments linked to your C code. So if you have something that you need assembly for you can still use it. So you really arn't giving up much by using C.

Just my 2 cents
Brent
 

csaba911

Member
You right about the division, I need 16*16=32 bit to store the result, and divide the result with 16 bit.
There is any good place for C guide :?: I tried a few years ago C++ for Dummies, give up in 4 days :oops: .
Something witch explain the very basic of the C for micros :!: what are this {};;; */

Thanks
STEVE
 

Agent 009

New Member
I think you better learn c++, although you seem not to like it very much. I think it's faster than assembly language to get to the point, though it could get messy when need of a very tiny specific functionality... If you ever consider learning C++, I advice you to get the Deitel's C++ How to program. I think the Deitel's editions for all languages is very easy to catch once one is willing to learn...
 

bmcculla

New Member
You right about the division, I need 16*16=32 bit to store the result, and divide the result with 16 bit.
There is any good place for C guide I tried a few years ago C++ for Dummies, give up in 4 days .
Something witch explain the very basic of the C for micros what are this {};;; */

"The C programming language" by Kernighan and Ritchie is a great reference book- maybe a bit dense for learning though. One of my computer science classes used a book that had C programming examples and the equivalent assembly (in MIPS but all assembly looks fairly similar)- with a little looking on barnes and Noble's website (they have a good technical books section) you should be able to come up with something like that.

C is the language of choice for 8 bit micros. C++ adds a bit too much overhead to be worth while in most cases. If you learn C learning C++ is easy because C++ is just an extension to C.

All the { } ; */ are just symbols to make the code more readable. The { starts a code segment - a loop for example, and the } ends that code segment. The /* */ surrounds comments which are notes by the programmer that are ignored by the compiler. And the ; ends each line.
 

csaba911

Member
I needed only a few days to understand the concept of assembler, after more than few week's C doesn't make sense !!
I think is to picky for the syntax and everything has it own rule...
I want to learn C, stack on assembler and my knowledge is not enough to create better, faster applications with asm, so I'm thinking C will help me to go forward.
Simply I worry, maybe on the end I'll now a little bit of asm, C, basic, and wont be enough to create something BIG.
Basic is limited and expensive, assembler to difficult and complicated but free, C is look like some alien language....!

Thanks for the reply's.

STEVE
 

StupidDum

New Member
I definitely go for C.
Unless you want a very precise timing or very accurate, efficient application, assembly language offer very little advantage.
In fact, writing assembly is time consuming, even if it makes your code efficient, it results in you entire programming process very inefficient.
 

ChriX

Member
I've only ever used assembly but i'd like to start programming in C. As stated above assembly seems very time consuming to me although you can do everything exactly as you want it.

Can anyone recommend a good book for programming PICs in C? The compiler I have at the moment is the C2C one from Picant.com, I understand there are different variations of C for PICs?
 

289u4ea

New Member
ChriX,

I found a good resource for beginning to understand C programming. I have gotten quite far using this book. It is free on line and can be down loaded at http://www.cctglobal.com go to the Sample Download area and look for C programming.

Take a look, it starts with the basics and proceeds from there. The book doesnt care which compiler you use.

Happy Programming!!

Gerry
 

csaba911

Member
Thanks
Definitely this guys address will burn in to my bookmarks.

Other vice for now, I'll continue using assembler, find some extremely useful apnotes and sample codes on Microchip website, it will do what I want from my current project.
If anyone need some help, check this microchip apnotes.
AN617
AN575
AN774
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top