Assembly or ....

Charles Noren noren at dinl.uucp
Thu Nov 24 03:18:28 AEST 1988


In article <1388 at aucs.UUCP> Andreas Pikoulas write:
>I would like to ask them if it really worth it to spend time to
>learn assembly language...

It is very much worth while to learn assembly language.  Reasons:

1.  Sometimes (although rarely) speed is absolutly crucial.  No matter
    how much you optimize your compiler switches, you cannot be
    absolutly assured you are getting the best performance (unless
    you observe the assembly or machine executable output of the
    compiler).  Even if the compiler gives you acceptable performance
    now, will a future upgrade of the compiler do something that will
    slow it down in the future?  Assembly lanaguage gives you absolute
    control.

2.  Assembly gives your more options to interface to your operating
    system, service interrupts, and control hardware.  It is true
    I can do all of this in most C's (even in many Pascal's), but there
    is a price.  Often the C compiler forces you to do things in certain
    ways.  Example, to service an interrupt in Turbo C, the Turbo C
    compiler will save all the registers, let you perform the operation,
    the restore all the registers.  In assembly,  you can save just the
    registers you need, perform a quick operation, the restore the used
    registers.  There may be ways around this in C, but often these use
    undocumented features of the compiler or other features which are
    subject to change.  I have been bitten by this many times when a
    new upgrade came to a compiler or operating system.

3.  Assmembly language gives you a better understanding of the architecture
    of the machine you are working on, in fact it forces you to learn
    the architecture.  If you are going to spend any time working on
    the machine this kind of knowledge will be of subtle but great benifit.
    This kind of knowledge can improve your high level language coding
    in a variety of ways (yes, you do want to make sure your coding is
    as much machine independent as possible).  For instance, in C you
    can use register variables.  But what are the practical implications
    if your machine has a limited number of general purpose registers?  On the
    x86 class machines there are a variety of memory models.  What are
    the real implications of using small, medium, large?  Knowing the
    assembly language will give you those insights.  Why can't you
    do a straight compare of pointers in C for equality in most memory models
    of x86 computers (but you can in some other CPU families)?  Knowledge
    of assembly will give you this answer (o.k., knowldge of the
    machine architecture gives you this answer, but knowledge of the
    assembly language forces you to learn the details of the architecture).

4.  It is good to know several different classes of languages.  It
    expands a person's thinking and approaches to solving problems.

This is a long winded reply.  I hope this helps.
-- 
Chuck Noren
NET:     ncar!dinl!noren
US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260,
         Denver, CO 80201-1260
Phone:   (303) 971-7930



More information about the Comp.lang.c mailing list