Maker Pro
Maker Pro

Assembly V.s. Compiler

T

Tanty

Jan 1, 1970
0
Why is assembly preferred over C++, say, in time critical applications?
Thanx
Tanty
 
W

Wouter van Ooijen

Jan 1, 1970
0
Why is assembly preferred over C++, say, in time critical applications?

That is a statement, not a question.


Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting
 
P

Pszemol

Jan 1, 1970
0
Tanty said:
Why is assembly preferred over C++, say, in time critical applications?

Because the execution time of a assembly code is known for the programmer
and is relatively easy to be predicted. When you write C++ code, the execution
time can be unpredictable - for example when you use dynamic object creation.
You have to be carefull with the memory management unpredicitbility in C++
You have a garbage collection and not always it is under the developpers control.
 
F

Frank Bemelman

Jan 1, 1970
0
Tanty said:
Why is assembly preferred over C++, say, in time critical applications?

What happened to C ? What is time critical ? If you need someting to time
down to the last processor clock, a piece of asm can help, but if you
don't mind a few microseconds of jitter, C is up to the job. For 99.99%
of all cases, asm is pointless.

Follow up to alt.religion ;)
 
J

John Larkin

Jan 1, 1970
0
What happened to C ? What is time critical ? If you need someting to time
down to the last processor clock, a piece of asm can help, but if you
don't mind a few microseconds of jitter, C is up to the job. For 99.99%
of all cases, asm is pointless.

Follow up to alt.religion ;)

But I make a lot of money off that remaining 0.01%!

John
 
J

Joel Kolstad

Jan 1, 1970
0
Pszemol said:
Because the execution time of a assembly code is known for the programmer
and is relatively easy to be predicted.

True for, e.g,. simple 8 bit microncontrollers. Not at all true for full
fledged contemporary processes where you predicting code execution time
requires knowledge of what's in the cache (and if not everything else going
on in your system -- good luck!), the branch prediction buffers, the TLBs,
etc.

Of course one could argue that 'time critical applications' are reasonable
to do on those 'simple 8 bit microcontrollers,' whereas something like a
modern PC tends to leave 'time critical' activities to hardware. Although
there are real time operating systems (RTOSes) out there that can provide
deterministic response times, but programming them is necessarily more
'rigid' than in, e.g., the Windows free-for-all.

---Joel Kolstad
 
F

Frank Bemelman

Jan 1, 1970
0
John Larkin said:
But I make a lot of money off that remaining 0.01%!

Glad you do! My latest post in comp.arch.embedded was a question
about, eh, assembler. I did some 68K assembler ages ago, playing
with my Atari ST, and that was reasonably comfortable. But doing
an 32 bit compare on an 8 bit uP, for the first time, without
a library at hand, is a labor intensive job. Same for writing
down a new algoritm. The rest remains the same, calling, looping,
jumping, for those things there isn't really that much diffence
between asm & C. I think I like C, because I can easier see the
programs flow from the sources. And it's less typing.
 
M

Mike Page

Jan 1, 1970
0
Tanty said:
Why is assembly preferred over C++, say, in time critical applications?
Thanx
Tanty

Do you mean time for the program to be coded, or executed ?
 
K

Kevin Aylward

Jan 1, 1970
0
Pszemol said:
Because the execution time of a assembly code is known for the
programmer and is relatively easy to be predicted. When you write C++
code, the execution time can be unpredictable - for example when you
use dynamic object creation.

So, dont do it then. The issue is usually because asm can be faster,
sometimes...
You have to be carefull with the memory management unpredicitbility in
C++

No. The amount of memory allocated in c++ is quite determistic.
You have a garbage collection and
not always it is under the developpers control.

c++ does not use garbage collection.

Kevin Aylward
[email protected]
http://www.anasoft.co.uk
SuperSpice, a very affordable Mixed-Mode
Windows Simulator with Schematic Capture,
Waveform Display, FFT's and Filter Design.
 
B

Ben Pope

Jan 1, 1970
0
Tanty said:
Why is assembly preferred over C++, say, in time critical applications?
Thanx


C++ is fairly bloated in terms of features for embedded work (which is
usually where time-critical lies) and can therefore be non-deterministic.
(error handling, for example)

I would use C for the most part, modern compilers are pretty damn good at
optimisation and with a little thought your C can be pretty quick. Code it
in C, look for where 90% of the time is being used (usually in 10% of the
code) and consider optimising that in assembler - usually you'll find that
you can optimise it in C pretty well.

Time critical does not mean fast however, so it really does depend on your
task.

I don't think that assembler is preffered for most applications (in my
experience it takes an awful lot longer to code, is more error prone and
leads to code that is not necessarily significantly more optimal than the
C).

For time-critical (real-time with hard constraints) you need determinism,
not necessarily speed.

Ben
 
P

Paul Burridge

Jan 1, 1970
0
Why is assembly preferred over C++, say, in time critical applications?

Because C/C++ (or any such language even though C is the least
offender in this regard) is necessarily bloated for the sake of the
programmer's convenience. That convenience saves the programmer time
at the cost of processor-time. With Assembler, OTOH, you can taylor
your needs precisely to the intended application. User-friendly it
ain't; but it's certainly lean and mean.
But *real* programmers program in machine code...
 
F

Frank Bemelman

Jan 1, 1970
0
Kevin Aylward said:
So, dont do it then. The issue is usually because asm can be faster,
sometimes...

C++

No. The amount of memory allocated in c++ is quite determistic.


c++ does not use garbage collection.

He probably means running an avalance of destructors, but only
a fool would let that happen inside a loop or interrupt that
is desired to be lean and mean.
 
P

Paul Burridge

Jan 1, 1970
0
No. The amount of memory allocated in c++ is quite determistic.

ISTR the heap memory handling ability of C is pretty crap though,
isn't it, Kev?
 
F

Frank Bemelman

Jan 1, 1970
0
Paul Burridge said:
ISTR the heap memory handling ability of C is pretty crap though,
isn't it, Kev?

That's a problem with any language that uses dynamic memory
allocation, so use it with care. Or write your own malloc/free
stuff if you're not happy with the one provided. This is
no better or worse with assembly language. In simple versions
of BASIC, you don't have a choice, and when the memory is
totally messed up, the garbage collector comes along, and
freezes your system for a while. Could take minutes, on very
old basics running on a slow PC-XT ;) Using the windows API,
it's actually not so bad, as you can can allow the system
to reorganize the memory, as long as you unlock & lock your
reserved block between acceses, in a way letting the OS know
that it is okay to move your block of memory elsewhere. Bad
apps often lock their blocks all the time, which is comfortable
but rude, as it limits the memory manager in doing it's job.
 
S

Svenn Are Bjerkem

Jan 1, 1970
0
Wouter said:
That is a statement, not a question.

No, it is his EE homework that he doesn't have the clue to research by
himself.
 
K

Kevin Aylward

Jan 1, 1970
0
Svenn said:
No, it is his EE homework that he doesn't have the clue to research by
himself.

Yes he does. He posted to this NG, and got lots of answers.

Kevin Aylward
[email protected]
http://www.anasoft.co.uk
SuperSpice, a very affordable Mixed-Mode
Windows Simulator with Schematic Capture,
Waveform Display, FFT's and Filter Design.
 
P

Paul Burridge

Jan 1, 1970
0
That's a problem with any language that uses dynamic memory
allocation, so use it with care. Or write your own malloc/free
stuff if you're not happy with the one provided. This is
no better or worse with assembly language. In simple versions
of BASIC, you don't have a choice, and when the memory is
totally messed up, the garbage collector comes along

"Garbage collector" - I love that term. :)
 
B

Ben Pope

Jan 1, 1970
0
Paul said:
"Garbage collector" - I love that term. :)

I don't see why you can't just be expected to write a destructor in much the
same way as you write a constructor.

I guess garbage collection is there to clear up after rubbish programmers,
shame it can't collect and dispose of them too :)

Ben
 
L

Luhan Monat

Jan 1, 1970
0
Paul said:
ISTR the heap memory handling ability of C is pretty crap though,
isn't it, Kev?
"Windows [n.], A thirty-two bit extension and GUI shell to a sixteen bit
patch
to an eight bit operating system originally coded for a
four bit
microprocessor and produced by a two bit company."

W.I.N.D.O.W.S : Will Install Needless Data On Whole System.

Luhan
 
O

onestone

Jan 1, 1970
0
Paul said:
"Garbage collector" - I love that term. :)

Yes but to be politically correct you must now refer to it as a
Sanitation Engineer.

Al
 
Top