[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Asm or C (was: Re: New Web browser for MiNT)



> > Well, I disagree. Having an example of myself here, I can say, that
> > assembler people probably don't code in asm just because it is considered
> > cool. They usually prefer assembler for its advantages over C or another
> > high level language. 
> 
> I am fully aware of the advantages of asm over C when it comes to speed
> and efficiency - however, these points aren't always valid ones. On many
> occassions (most common interactive applications) a slight speed loss does
> not matter and the advantages of a more portable and easily maintained 
> program far outweigh the speed advantages.

Yes, right. Slight speed gain that breaks portability is quite bad usage
of assembler. But if you have a portable C program and a non-portable
assembly based equivalent is say 5-6 times faster on a particular machine
(Atari), I am totally for the assembler. At the other hand, when things go
to Atari and MiNT, a GEM based browser may be written in assembler quite
safely, because in current circumstances a GEM application is not portable
by definition, whatever language is used.

> > coding the same in C is a pain for you. Though I haven't been ever on the
> > scene, I think that scene programming experience is useful here, because
> > you also know most of optimal structures for data processing by heart.
> 
> This is definitely true. Naturally I'm a great friend of scene stuff and
> didn't mean to imply that it's a bad thing - quite the opposite! Just that
> even scene people have to realize at some point that assembler isn't the 
> One and Only Programming Language (even the game coders I know code mostly
> in C while hand-optimizing critical parts in asm).

You're definitely right. But it does not make sense to force people to
write stuff in a language unknown for them just because C exists. If a
program is planned to work on a particular machine with a particular
operating system (Atari/m68k/MiNT/GEM) and it is intented to be optimal
for such a configuration and nothing else, I don;'t think writing it
totally in assembler would be a bad idea. Even if written in C, it would
be practically not portable to anywhere, but slow/big/unefficient for
sure. When things come to a browser, we already have one written in a
"portable" language for more than one operating system and more than one
TCP stack. Well, CAB is compact and lightspeed when compared to a
Netscape, but I believe a browser may be even more compact and
efficient, and this is the point.

You may consider this horrible, but I wrote some very small utilities
(like fastboot.prg) for MiNT and I wrote them in assembler. Of course, the
only real advantage it the length of object code (few k or even less than
1 k), because when a program does notning but system calls, you can't
speak about speed. So I could really write such things in C. But I used
assembler because IT WAS EASIER for me to use asm, than anything else ( =
than C, because I don't know Pascal and I never bothered to learn GFA
BASIC; I came from 8-bit world where we wrote all serious programs in
assembler, so it was natural thing for me to jump into m68k assembler
passing by everything else).

For larger programs I noticed that the time of development for asm
programs is really much longer than for C programs. But I also noticed,
that the most of this time is spent on optimization, which part is mostly
missing for C development.

> > Programming in assembler is as easy (or: as hard) as in other languages,
> > the only problem with assembler (that it is considered hard) is that
> > people don't know assembler. 
> 
> This is not purely true. There is a clear reason why high-level languages
> were developed - easiness and fast development times. When dealing with
> large and possibly complex structures it is obviously easier the more
> abstract you can make the operations, without having to deal with every
> single minor operation or the operations of the hardware.

Yes. There are two points of view. From one hand, if you want to deal with
complex data structures, a high level language may be easier for you to
code ideas. At the other hand, no compiler has an ability to do miracles
and a code based on an abstract data structure won't be fast. Even worse,
if a high level language makes you to think using such an abstract
structures (bad example: my friend has once written a program in Pascal,
that used a dynamical table of files of records of something-i-forgot or
something terrible like this in order to access 9 data files on the disk;
no wonder why the program was terribly slow even on his pentium 266), you
loose an ability to write an optimal program for any computer.

The other point of view provides simplification of complex & abstract
structures to "natural" machine data strucures like registers, linear
tables of bytes/words/longwords and stack. Of course, if you reduce the
problem to this (compilers usually do the same, but according to your own
words, they can't optimize optimally, so they don't do it perfectly),
assembler programming gets easy.

> > - assembler programs are short. A simple GEM application (cleanly written)
> >   takes few kilobytes including Devpac AES & VDI data structures.
> > - assembler programs are fast. If you have an intensive task which uses
> >   several variables and pointers in a loop, the assembler gives you an
> >   easy possibility to access 15 32-bit registers. If you put all your 
> >   variables there, your code will be lightspeed when compared wit a C
> >   compiled equivalent with 2 accessible registers and the rest of
> >   variables stored in the memory.
> 
> I am quite aware of these points. The second point was slightly vague,
> however: why on earth would a C compiler only use 2 registers???

I always wondered the same. A register is an important resource, and it
seems you're not able to use this resource in a big extent while
programming in C on Atari. That's very bad.

> In fact modern processors and compilers are beginning to be so complex
> that coding asm isn't even worth it. You may get a speed bonus but the
> amount of time used to do that is quite a bit.

Well, even some old processors (e.g. Intel) were quite hard to program in
assembler. But really, that has nothing to do with a level of difficulty
when you're using m68k...

> > Also it is much easier (at least for me) to develop programs written
> > totally in assembler instead of mixed C & asm. Just because interfacing
> > the code from C to asm is pure pain and wastes the CPU time (you have to
> > push variables to the stack, then call teh assembler module with jsr, then
> > pull everything back, do the job, then do rts in order to be back to the 
> > C).
> 
> You may need to do that, but in the name of portability and extensibility,
> I'd say it's worth it. Have you checked out the inline assembler
> possibilities gcc offers? I haven't, but they may offer some useful
> functionality when it comes to mixing asm with C code.

I have to admit, that I have never checked the inline asm in C. I saw few 
examples of it in C sources (MiNT, MiNT Libs) and well... the syntax just
scared me out.

> I am familiar with assembler and there is no way anyone can
> convince me it's easier than C (the more abstraction available, the
> easier things are - I think should be quite obvious even to an asm
> programmer).

See above, this is a question of data structures you are used to think of.
If you reduce abstraction to reality, assembler gets easy. If one is used
to reduce abstract problems to natural data structures the machine really
supports, the abstraction offerred by high level languages doesn't seem
deadly useful anymore. And the price you have to pay for the abstraction
suddenly starts to seem too high.

> Another point that should be noticed is that it makes a lot of sense
> teaching C in schools. Teaching just m68k assembler would be ridiculous.
> What if you suddenly end up on a RISC UNIX machine and have to code
> something? Wont be much help knowing m68k assembler then.. (yes, after
> learning the basics of programming, any language can be learnt easily, but
> why go for a less-useful one when you can go for a useful on?).

I didn't say that teaching C in schools is a bad thing. I only said that
it is one of reasons why it seems easier. Just because people usually get
in touch with the C very early (at school) and have contact with C
programs very often. Here, if you ask a student, what is easier, Pascal or
C, you will hear "Pascal". Just because Pascal is taught in high schools
all the time, while they have only few C lessons. And that has nothing to
do with the question, which of these two languages is really "easier".

The same with assembler.

Konrad M.Kokoszkiewicz
mail:draco@bl.pg.gda.pl
http://www.orient.uw.edu.pl/~conradus/

** Quem Iuppiter vult perdere, dementat prius.
*******************************************************
** Kogo Jowisz chce zgubic, temu wpierw rozum odbiera.