Newsgroups: comp.software-eng,comp.object,comp.lang.ada,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsfeed.cit.cornell.edu!newsstand.cit.cornell.edu!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!newsfeed.internetmci.com!news.sprintlink.net!EU.net!news2.EUnet.fr!news.fnet.fr!ilog!news
From: haible@laplace.ilog (Bruno Haible)
Subject: Re: Re C as portable assemble (was Re: Ethics in programming (was Re: Poetry in programming (Was: Re: Comparing OO against Structured Methodologies)))
In-Reply-To: mfinney@inmind.com's message of 21 Oct 1995 17:53:12 GMT
Message-ID: <HAIBLE.95Oct26201801@laplace.ilog>
Lines: 67
Sender: news@ilog.fr
Nntp-Posting-Host: laplace
Bcc: haible
Cc: <mfinney@inmind.com>
Organization: ILOG S.A., Gentilly, France
References: <456e5q$3kve@news-s01.ny.us.ibm.net> <45h5gt$lom@taco.cc.ncsu.edu>
	<chris.morgan-1410951607480001@baesema4.demon.co.uk>
	<813688854snz@wildcard.demon.co.uk> <45r6ug$pl5@felix.seas.gwu.edu>
	<45to13$6hn@natasha.rmii.com> <4662m6$ng2@caleddon.dircon.co.uk>
	<chris.morgan-2010951608180001@baesema4.demon.co.uk>
	<468pr0$c0s@saba.info.ucla.edu> <468q9m$c2m@saba.info.ucla.edu>
	<chris.morgan-2110951325550001@baesema4.demon.co.uk>
	<46bc28$to7@mujibur.inmind.com>
Date: 26 Oct 1995 19:18:01 GMT
Xref: glinda.oz.cs.cmu.edu comp.software-eng:38257 comp.object:39906 comp.lang.ada:36543 comp.lang.lisp:19733


Michael Lee Finney <mfinney@inmind.com> writes:

   >The phrase portable assembler describes C perfectly.

   I have to take exception to this.  I have seen people state
   this over and over and it is flat wrong.

This phrase is most often meant in the sense: "If you want to do
low-level programming _and_ be portable, use C."

It also means that C is used as a target language by compilers: Many
high-level language implementations nowadays compile to C and then use
the C compiler for the rest of the work, because the C compiler knows
the CPU and its registers and addressing modes etc. much better than
any freshly written machine code generator.

   What it does NOT contain that assembler languages
   contain, as a rule of thumb, are...

      1. Registers.  The "register" keyword doesn't count because
   it isn't really specifying a register.  It is just giving the 
   compiler an optimization hint.

      2. Many operators.  Where are the arithmetic right shifts?
   Certainly (as per the standard) not in C.  The vendor may
   or may not choose to provide them.  Where are the rotates?
   Where is the ability to have label variables -- so that you
   can directly implement things like the switch control
   structure at a low level.

   [...] It would have available
   the ability to explictly sign or zero extend values.  It would
   have the X * X -> XX (single precision input to double precision
   output using two registers) type of multiplication which is essential
   to efficient implementation of unbounded arithmetic precision
   packages.

You should look into GNU C and its __asm__ extensions. From within C,
it lets you specify any register for a C variable (local or global).
Arithmetic right shifts, zero extends, sign extends are covered by C,
you just have to use signed or unsigned types.

Rotates are known to GCC: If you write

      unsigned long x;
      x = (x >> 5) | (x << 27);

GCC will generate a rotate instruction if the CPU has one. On the
68k, GCC even knows about the "swap" instruction (16 bit shifts).

The X * Y -> ZZ multiplication is known to GCC as well: Write

      unsigned long X = ...;
      unsigned long Y = ...;
      unsigned long long ZZ = (unsigned long long) X * (unsigned long long) Y;

What gcc lacks is the ability to specify argument passing conventions,
such as "parameter x is passed in A2, parameter y in D5".


----------------------------------------------------------------------------
Bruno Haible                            net: <haible@ilog.fr>
ILOG S.A.                               tel: +33 1 4908 3585
9, rue de Verdun - BP 85                fax: +33 1 4908 3510
94253 Gentilly Cedex                    url: http://www.ilog.fr/
France                                  url: http://www.ilog.com/
