Searching \ for 'C or asm?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/language/index.htm?key=asm
Search entire site for: 'C or asm?'.

Truncated match.
PICList Thread
'C or asm?'
2006\02\18@090105 by Juan Cubillo

flavicon
face
Hello list,

What language would you guys consider as better for general (hobby-like) aplications?

I'm trying to learn assembler by myself, but I'm also learning c++ at school. Should I stay with c at this moment and forget about asm?

Thnkz
Juan Cubillo



2006\02\18@135825 by David VanHorn

picon face
>
>
> I'm trying to learn assembler by myself, but I'm also learning c++ at
> school. Should I stay with c at this moment and forget about asm?


This is one of those "religious war" questions.

I would tell you to learn both, and use both.

C is good for more complicated functions, and gets you away from thinking
about the details of the machine.

ASM forces you to think about the details of the machine.

The thing is, that the details never go away, they just get hidden.

In C, the problem X=835/967 looks trivial. In assembler, you'll see how ugly
that is, and you'll look for a way to do what you need to without the ugly
divide.

You're also more concious of spending ram, and the time each operation
takes, in ASM.

2006\02\18@141646 by John Nall

picon face
David VanHorn wrote:
> This is one of those "religious war" questions.
>
> I would tell you to learn both, and use both
>  

.
Doesn't seem like it should be a religious war, though, because the
answer you gave is so obviously correct that it is very difficult for me
to understand how anyone could argue with it.  Although perhaps that is
what a religious war is -- different people having different views, and
each one convinced that his view is obviously correct.  :-)
.
John

2006\02\18@153610 by David VanHorn

picon face
>
>
> Doesn't seem like it should be a religious war, though, because the
> answer you gave is so obviously correct that it is very difficult for me
> to understand how anyone could argue with it.  Although perhaps that is
> what a religious war is -- different people having different views, and
> each one convinced that his view is obviously correct.  :-)


:)  I'm surprised that the responses have been so sparse. Perhaps everyone's
away from their keyboards.

I do all my projects in assembler. I am learning C, but I am reluctant to
use it in any real project, because I see that it adds a couple of layers of
problems to the mix.  I don't have to worry about compiler bugs, or what the
compiler will make out of my code.  I don't have to worry that changing one
statement will cause some "ripple effect" and make changes elsewhere because
the optimization now works out differently.

Frankly, I'm surprised at the relatively primitive level of the compilers
I've seen. Optimization seems pretty poorly done.

Part of it I'm sure, is how I was brought up, but I think the exposure to
the machine's internals is very important.  "Buy a bigger chip" isn't always
an option, and sometimes you really need all the performance you can get,
and a compiler isn't going to do your thinking for you here.. You have to
know what's the fastest way to get something done on THIS machine.

2006\02\18@160701 by Harold Hallikainen

face picon face

> Hello list,
>
> What language would you guys consider as better for general (hobby-like)
> aplications?
>
> I'm trying to learn assembler by myself, but I'm also learning c++ at
> school. Should I stay with c at this moment and forget about asm?
>
> Thnkz
> Juan Cubillo

I'm currently writing small applications in asm. Large applications are
written in C with the interrupt service routines in asm. There are a few
non-ISR functions that are just too slow in C, so I also write them in
asm. So... I think we need both! Also, to do any I/O, you're going to have
to be pretty familiar with the hardware, which gets you pretty close to
asm anyway.

Harold


--
FCC Rules Updated Daily at http://www.hallikainen.com

2006\02\18@161220 by David VanHorn

picon face
>
>
> I'm currently writing small applications in asm. Large applications are
> written in C with the interrupt service routines in asm. There are a few
> non-ISR functions that are just too slow in C, so I also write them in
> asm. So... I think we need both! Also, to do any I/O, you're going to have
> to be pretty familiar with the hardware, which gets you pretty close to
> asm anyway.


I think this is pretty much the idealized model.
Hand-code the fast stuff.

2006\02\18@173432 by Peter Todd

picon face
On Sat, Feb 18, 2006 at 03:36:09PM -0500, David VanHorn wrote:
> :)  I'm surprised that the responses have been so sparse. Perhaps everyone's
> away from their keyboards.
>
> I do all my projects in assembler. I am learning C, but I am reluctant to
> use it in any real project, because I see that it adds a couple of layers of
> problems to the mix.  I don't have to worry about compiler bugs, or what the
> compiler will make out of my code.  I don't have to worry that changing one
> statement will cause some "ripple effect" and make changes elsewhere because
> the optimization now works out differently.

I use SDCC, and I will say I have run into a number of compiler bugs. It
sucks, a hell of a lot, and you gotta know assembly to be able to
convince yourself that it really is the compilers fault. Usually I'll
find some behavior that I think is impossible, so I'll read the interm
.asm files the compiler makes, and see what things look like. Usually
everything looks right and it's some subtle bug somewhere else, but
sometimes you see really weird stuff that's probably a compiler bug.
Recode to get around it. This has only happened when I've done really
weird stuff, like used piles of goto's to make a state machine...

That said. I use C for everything I possibly can. Most of the stuff I
make isn't speed critical, I also don't make many copies of it, so the
extra money for a big, fast, 18F chip verses a carefully optimized 12F
asm implementation is *well* worth it. Lifes too short to write asm.

I'm actually investigating other types of microprosessors right now,
like 8050's and the Atmel chips. I'd like to find something better
supported by the free compilers I can get, for more complex projects.

> Frankly, I'm surprised at the relatively primitive level of the compilers
> I've seen. Optimization seems pretty poorly done.

I agree %100! Man, the stuff I've seen, and I've yet to figure out how
to do inline functions in SDCC, it's not in the documentation anywhere,
and the included libraries don't ever use the inline keyword...

> Part of it I'm sure, is how I was brought up, but I think the exposure to
> the machine's internals is very important.  "Buy a bigger chip" isn't always
> an option, and sometimes you really need all the performance you can get,
> and a compiler isn't going to do your thinking for you here.. You have to
> know what's the fastest way to get something done on THIS machine.

Well even with my attitude of "what's the biggest chip I can fit?" I'm
very glad I've done plenty of asm programming too. It's nice to know
that my lazy use of floating point in some code is really slow, so I
know to look there first if I need to speed something up.

Another thing I find that helps is to prototype stuff on PC's first. I
like to use a graphical programming language called pure data to make
mockups of the behavior of my projects. It's really easy to write
complex things in it, so I get an idea of if I want to build the project
at all.

One day I might even go as far as to write algoritms on the PC first,
have never needed to yet, but it sounds like a good idea to me. Linux
can do hard-realtime stuff with the RTLinux extensions, so I can see
myself making stuff with commercial IO cards and plug those into
circuitry with all my code running on the PC.

Premature optimization is the root of all evil...

--
spam_OUTpeteTakeThisOuTspampetertodd.ca http://www.petertodd.ca

2006\02\19@033544 by Lindy Mayfield

flavicon
face
Would you say also that a factor is that the C used on a Pic chip is quite different from the C or especially C++ used on Windows or Unix?

I had a look at Pic C for a few minutes and for me it was like a whole different language.

{Original Message removed}

2006\02\19@122847 by Bill & Pookie

picon face
The Pic assembler is a good first assembler to learn.  It has most of the
directives of other assemblers although they may be called other names.  It
also would teach you to produce a hex file (object file) and how to use a
linker if you so chose.  And you  will become aware of how I/O devices such
as a uart work.

The low end Pic instruction set is very small and each does just one thing
and has no special cases or modifiers.  The exception is that some
instructions allow you to override the default and put the result in the W
or File register.  So the instructions are much easier to learn.

A difference between the low end Pic and "Real Computers" is  that the Pic
is more bit orientated while other computers are byte or word devices.  Also
because of limited instruction set, many things can not be done with a
single Pic instruction.

But as you learn new stuff, you draw from the old stuff you have learned and
this makes things easier.  So while low end Pic assembly may/may not be
necessary, you will become comfortable with it and producing running code
much quicker than with a "Real Computer"

Bill

And Juan, Pookie wants me to ask if you had two feet of snow there last
week.  She is looking for a warmer place.


----- Original Message -----
From: "Juan Cubillo" <.....jacubilloroKILLspamspam@spam@costarricense.cr>
To: <piclistspamKILLspammit.edu>
Sent: Saturday, February 18, 2006 6:05 AM
Subject: C or asm?


{Quote hidden}

2006\02\19@124540 by Tomas Larsson

flavicon
face
I think it's important to know and use both of them.
The right tool for the right purpose, it is not a question of either or, but
both.
You need them, simply because you cant do everything in C, but its possible
in asm.
However, to avoid reinventing the wheel use C for the bulk, and asm when
it's not possible or economical to use C.

With best regards

Tomas Larsson
Sweden
http://www.naks.mine.nu for downloads etc.
ftp://ktl.mine.nu for uploads. Or use the free http://www.yousendit.com service.

Verus Amicus Est Tamquam Alter Idem

> {Original Message removed}

2006\02\21@090620 by abhishek dikshit

picon face
sir,
      The question is time and effort you wanna put in.
         C has the followiig advantages
         1very simple code (u r already familiar with c++ =>advantage)
         2 No need to get to the architecture ,consider it as a black box.
         Assembly has its own advantage of knowing the
microcontroller in and out ,and ofcourse its much faster.
        However if you are considering simple programs on uart,i/o
etcd i would def suggest C.
        you can actually begin with C18 for any of the 18xxxx
series.A lot of examples  on net will surely benefit you. C18
available on microchip
Yours Sincerely
Abbymain

2006\02\21@121929 by M. Adam Davis

face picon face
On 2/18/06, Juan Cubillo <.....jacubilloroKILLspamspam.....costarricense.cr> wrote:
> What language would you guys consider as better for general (hobby-like) aplications?

C.
This from the assumption that by "general hobby like applications" you
mean low volume projects which you want to start and finish as quickly
and easily as possible.

> I'm trying to learn assembler by myself, but I'm also learning c++ at school. Should I stay with c at this moment and forget about asm?

Do NOT forget about or try to avoid ASM - not on the PIC.  Especially
if you plan on using a C compiler for which you get little support.
It will be to your advantage to duplicate your work for several small
projects (blink an LED for instance) in both C and ASM so when you
have to debug your C program you feel confidant when you look at the
compiled ASM listing.

This is not to say at all that C is better than ASM or vice versa,
just that the way you framed the problem suggests the better solution
is likely to be C.

The issue with C on the PIC is that the PIC's architecture is not
nearly as optimized for C as most processors developed in the last
10-20 years have been.  C compilers, especially good ones, for the PIC
are non-trivial.  Many , if not most, compilers make comprimises with
the C language, and extend it in non-standard ways to make it easier
to have a high performance program run on the PIC that was written in
C.

I suggest starting out with a reliable commercial C compiler if you
want to avoid assembly at the beginning.  Several companies have a
free version with code size or chip limitations.  I've used the
compilers from http://www.bknd.com/ very successfuly in the past.

You should not focus on C and completely neglect assembly.  They both
have strengths and weaknesses and under different situations you will
find one is the better choice.

Also keep in mind that great programs often use both.  I develop my
prototypes in C for rapid development and testing (and to force, er
'help' the customer settle on the specification), then optimize the
project according to the specification.  This may involve porting the
program to a different architecture (difficult, at best, in assembly),
optimizing sections of the program to assembly, or re-writing the
entire program in assembly by hand for performance or cheaper chip
reasons.

Good luck, and have fun!

-Adam

2006\02\22@034238 by William Chops Westfield

face picon face
On Feb 21, 2006, at 6:06 AM, abhishek dikshit wrote:

> The question is time and effort you wanna put in.
>    C has the followiig advantages
>    1 very simple code (u r already familiar with c++ >advantage)
>    2 No need to get to the architecture, consider it as a black box.
>

Argh!  Several times I have composed a message on this subject, only
to delete them as I decided not to enter into the fray.  But I can't
take it any more...

Historically, learning the "architecture" of a CPU has been tightly
associated with learning the assembly language associated with that
CPU, and "High level languages" insulated you not only from the
assembly language details, but also from anything having to do with
the hardware at all.  Want to write to a card punch instead of a
magtape from your fortran progam?  Change the JCL (which was entirely
external to the fortran program itself.)

Along came microcomputers and microcontrollers, and changed everything.
Suddenly, people wanted to control the hardware details themselves.

Using a high level language to program a microcontroller will NOT
prevent you from having to learn a good deal about the "architecture"
of the chip.  A PIC controls everything via its registers, and you
have to know what that MEANS to get anywhere, even in C.  You'll need
to learn things about bits and bytes and word sizes that were
traditionally only taught in assembly language classes.  You'll need
at least a bit of assembly "knowledge" just to understand the
datasheets.  C will allow you to neglect some of the finer details.
On PICs, it particularly prevents you from needing to know much
about banks or pages (which is good.)  But you can't get by without
knowing anything about the architecture (with the possible exception
of cases where there are copious libraries that provide you with a
sort of "virtual" architecture.)

It's not clear to me that a background in C++ on a large GUI
operating system is of much use in learning C for a microcontroller.
The emphasis is too ... different.  In a GUI application, you are
spending a majority of your time interacting with the operating
system and library environment, and less with the CPU or hardware
itself...

It's like... I remember when the world was just starting to do
"interactive" programs (rather than batch data processing.)  And
I'd read language manuals (basic, fortran, algol, pascal, etc) and
they'd go on and on about how wonderfully elegant their language
syntax was, and I'd be thinking "yeah, yeah, but can it do raw IO
to a CRT terminal or not?"  (which would be buried somewhere hard
to find, of course.)  Grr.  Learning a LANGUAGE, whether it's assembly
or a HLL, is a DIFFERENT task than learning to manipulate a
microcontroller.  You need A language PLUS the microcontroller
specifics to accomplish anything.  (heh.  unless, like the PDP11
portion of an assembly class I took, you set up registers, run a
simulator, and see if the right results are in other registers. Yuck!)

BillW

2006\02\22@120138 by Juan Cubillo

flavicon
face
Thank you very much for a very complete answer.       Juan Cubillo

-----Original Message-----
From: "abhishek dikshit"<EraseMEabbyait63spam_OUTspamTakeThisOuTgmail.com>
Sent: 2/21/2006 8:06:18 AM
To: "Microcontroller discussion list - Public."<piclistspamspam_OUTmit.edu>
Cc:
Subject: Re: C or asm?

sir,
      The question is time and effort you wanna put in.
         C has the followiig advantages
         1very simple code (u r already familiar with c++ =>advantage)
         2 No need to get to the architecture ,consider it as a black box.
         Assembly has its own advantage of knowing the
microcontroller in and out ,and ofcourse its much faster.
        However if you are considering simple programs on uart,i/o
etcd i would def suggest C.
        you can actually begin with C18 for any of the 18xxxx
series.A lot of examples  on net will surely benefit you. C18
available on microchip
Yours Sincerely
Abbymain

2006\02\23@180639 by Juan Cubillo

flavicon
face
thanks for the advice

juan cubillo

-----Original Message-----
From: "M. Adam Davis"<@spam@stienmanKILLspamspamgmail.com>
Sent: 2/21/2006 11:19:27 AM
To: "Microcontroller discussion list - Public."<KILLspampiclistKILLspamspammit.edu>
Cc:
Subject: Re: C or asm?

On 2/18/06, Juan Cubillo <RemoveMEjacubilloroTakeThisOuTspamcostarricense.cr> wrote:
> What language would you guys consider as better for general (hobby-like) aplications?

C.
This from the assumption that by "general hobby like applications" you
mean low volume projects which you want to start and finish as quickly
and easily as possible.

> I'm trying to learn assembler by myself, but I'm also learning c++ at school. Should I stay with c at this moment and forget about asm?

Do NOT forget about or try to avoid ASM - not on the PIC.  Especially
if you plan on using a C compiler for which you get little support.
It will be to your advantage to duplicate your work for several small
projects (blink an LED for instance) in both C and ASM so when you
have to debug your C program you feel confidant when you look at the
compiled ASM listing.

This is not to say at all that C is better than ASM or vice versa,
just that the way you framed the problem suggests the better solution
is likely to be C.

The issue with C on the PIC is that the PIC's architecture is not
nearly as optimized for C as most processors developed in the last
10-20 years have been.  C compilers, especially good ones, for the PIC
are non-trivial.  Many , if not most, compilers make comprimises with
the C language, and extend it in non-standard ways to make it easier
to have a high performance program run on the PIC that was written in
C.

I suggest starting out with a reliable commercial C compiler if you
want to avoid assembly at the beginning.  Several companies have a
free version with code size or chip limitations.  I've used the
compilers from http://www.bknd.com/ very successfuly in the past.

You should not focus on C and completely neglect assembly.  They both
have strengths and weaknesses and under different situations you will
find one is the better choice.

Also keep in mind that great programs often use both.  I develop my
prototypes in C for rapid development and testing (and to force, er
'help' the customer settle on the specification), then optimize the
project according to the specification.  This may involve porting the
program to a different architecture (difficult, at best, in assembly),
optimizing sections of the program to assembly, or re-writing the
entire program in assembly by hand for performance or cheaper chip
reasons.

Good luck, and have fun!

-Adam

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...