Newsgroups: alt.folklore.computers
From: mfriedma@uucp (Michael Friedman)
Subject: Re: The need for an assembler (was: Favorite CPU)
Organization: Oracle Corporation
Date: Thu, 20 Aug 1992 16:49:00 GMT
X-Disclaimer: This message was written by an unauthenticated user
              at Oracle Corporation.  The opinions expressed are those
              of the user and not necessarily those of Oracle.

In article <5242@unixhub.SLAC.Stanford.EDU> ralph@falcon.SLAC.Stanford.EDU (Ralph Becker-Szendy) writes:
>In article <1992Aug19.160844.13884@auto-trol.com> davgot@auto-trol.com 
>(David Gottner) writes (edited):
>>I have complete control of the hardware with some HLL's (like C).  If I want
>>a left shift I use '<<'.  If I want a signed multiply I use '*' on two signed
>>numbers.  What more control could I want?

>>I suppose that there are >>some<< limitations.  You can't write interrupt
>>routines with standard C, but that is what assembler is for.  However, C
>>gives you so much control that assembly is rarely necessary.

>Nonsense. There are many (efficient!) things you can do in assembler
>but not in C. And I'm sure even the best optimizing compilers don't
>know all the tricks you can pull in assembler.

>- If I call any subroutine or function in C, a large set of registers
>  will be saved in some fashion, often unneccesarily.

And in just how much of your code is this an important issue?  I don't
think anyone denies that assembly can be a massive performance win if
you use it in a tight loop that takes up most of your execution time,
but most code isn't in tight loops that take up most of your execution time.

>- When I want to test a particular bit in assembly language, I have
>  several ways of doing it (in the Z80 for example I can rotate if it
>  was the first or the last bit, I can mask and test, or I can do a bit
>  test instruction). In some situations, some of these ways may be
>  better than others. How do you
>  express these minute differences to your C compiler ?

You don't.  Once again, unless speed is absolutely critical you don.t
need to, and even in those applications in 99% of the code it doesn't
make a difference.

>- If there is a useful routine (like output a character) which is
>  provided with a strange calling sequence (the character has to be in
>  register X and a function code in register Y), I can not use it from
>  within C, because there is no general way to express all possible
>  calling conventions. 

If the C library is implemented right then putc will call that function.

>  If I even touch
>  putc or printf I am deep in the mess of a horrible run-time-library,
>  which is liable to be a lot less efficient.

So what?  Once again, in what percentage of your code is this a
significant issue?

>- If I need a really tight timing delay loop (say a microsecond), I
>  just sit down with the CPU manual, count clock cycles, and do the
>  correct number and type of instructions (pick the correct instructions
>  to get the right number of clock cycles). I vaguely remember doing
>  that for HOURS to get a tape reading program to work exactly right.
>  How do you do this in C ?

You don't.  You don't do it in assembly either unless you're writing a
one-time application or you have absolutely no choice.

What the heck are you going to do when your customer gets a clock
speed upgrade?  Or a processor upgrade?  Or faster memory so that the
instructions get loaded faster?

>So, C is not the answer to all questions. There are LOADS AND LOADS of
>things which can not be expressed in C; and there are some thing which
>any HLL compiler will do less efficiently than handcoded assembly.

Of course.  On the other hand, I'll bet that less than .1% of code is
appropriately assembler and less than .001% of applications are
appropriately 100% assembler.

>Note: I am not advocating writing everything in assembler. That's
>crazy. But good hand-coded assembler still has its place, in
>particular in the tight spots of device drivers and realtime systems
>(where every clock cycle counts). Therefore I agree that assembler is
>RARELY neccessary.
-- 
-------------------------------------------------------------------------------
I am not an official Oracle spokesman.  I speak for myself and no one else.