Author Topic: Anyone else think assembly is (mostly) useless?  (Read 32086 times)

0 Members and 1 Guest are viewing this topic.

Offline jmole

  • Regular Contributor
  • *
  • Posts: 211
  • Country: us
    • My Portfolio
Anyone else think assembly is (mostly) useless?
« on: April 30, 2013, 01:53:34 am »
So, while I think it's very beneficial to know assembly, I have never found a place where it was necessary to use assembly in a real design.  i.e., most bottlenecks that you'll find in an embedded system have more to do with the architecture design and technology choices rather than that one damn piece of C code that won't run fast enough.



Edit: I made a quick video on this topic. Not, by any means, a thorough comparison of assembly and C code, but it shows that while knowledge of assembly is very useful, often the compiler will do a good enough job (with well written code) that you don't need to use it.

« Last Edit: April 30, 2013, 09:01:05 pm by jmole »
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4401
  • Country: au
  • Question Everything... Except This Statement
Re: Anyone else think assembly is (mostly) useless?
« Reply #1 on: April 30, 2013, 02:13:31 am »
knowing assembly is mainly about being able to either speed up or shrink down a piece of code better than a compiler can do, though this generally follows the tradeoff of removing easy portability,
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: Anyone else think assembly is (mostly) useless?
« Reply #2 on: April 30, 2013, 02:14:00 am »
Perhaps that is what you meant by "mostly useless", Assembly needn't be used most of the time these days.

This. Assembly is useless in the same way that a toilet plunger is useless - you don't use it often (at least, hopefully...), but damn does it come in handy when you do need it.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline chickenHeadKnob

  • Frequent Contributor
  • **
  • Posts: 829
  • Country: ca
  • doofus programus semi-retiredae
Re: Anyone else think assembly is (mostly) useless?
« Reply #3 on: April 30, 2013, 02:16:03 am »
I would take it you have never coded interrupt handlers in systems where interrupt latency and jitter matter. Every cycle counts in many of the projects I have worked on. Also have had to diagnose and correct object code generated by buggy compilers.

Have I just taken the bait of troll?  :palm:
« Last Edit: April 30, 2013, 10:24:42 am by chickenHeadKnob »
 

Online BravoV

  • Super Contributor
  • ***
  • Posts: 6276
  • Country: 00
Re: Anyone else think assembly is (mostly) useless?
« Reply #4 on: April 30, 2013, 02:19:27 am »
But if it is a question of using Assembly to squeeze the code to fit a chip then you should consider a bigger chip.

What "if" its not your call to decide which chip to use, say budget constraint or the boss said that you must use cheap underpowered chip ?  Thats the reality and what true pros do for living.

Rarely used nowadays, mostly perceived by noob as useless but still well respected by experienced users, once needed, you just can't live without it.

Offline ecat

  • Frequent Contributor
  • **
  • Posts: 296
  • Country: gb
Re: Anyone else think assembly is (mostly) useless?
« Reply #5 on: April 30, 2013, 02:42:48 am »
A basic knowledge of architecture and assembly language is a very useful thing to have and a whole lot of that knowledge is transferable between processors so it keeps on giving.

To all the reasons mentioned above I'll add analysing compiler output for common operations and constructs helps with writing  efficient code while imposing minimum inconvenience.
 
 

Offline helloworld922

  • Regular Contributor
  • *
  • Posts: 57
  • Country: us
    • My personal blog
Re: Anyone else think assembly is (mostly) useless?
« Reply #6 on: April 30, 2013, 03:35:48 am »
Assembly is useless in the same way that a toilet plunger is useless - you don't use it often (at least, hopefully...), but damn does it come in handy when you do need it.

Nice analogy, and I agree with this :)

Even if you don't end up writing assembly code, I sometimes use dis-assemblers to take a closer look at critical sections of code generated by the compiler (I even do this occasionally on PC programs!). This can help me determine if there isn't a better way to write my C code, or if the best choice is to use assembly code. These are extreme cases where I want as much performance as I can possibly get out of my hardware as possible.

So, yes I don't use assembly much, but when just using C code isn't possible, I would rather read/write assembly code over having to read/write machine code any day.
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2062
  • Country: au
    • DIGSYS
Re: Anyone else think assembly is (mostly) useless?
« Reply #7 on: April 30, 2013, 03:51:41 am »
I've been writing in Assembly for 40+ yrs, and never get tired of it. Yes, I've tried just about every other language out there (usually to
fit in with some system I'm adapting to), but never could put up with all their limitations / idiosyncrasies. Yes, you can mix and match,
but what a mess that can end up in, especially when a few programmers are involved. I'm fine with it.

The VERY OLD argument ... "well just use a bigger chip" has been going on since I STARTED and never seems to go away.
It starts with .. use a slightly bigger chip / more IO / RAM ---> then .. use a DIFFERENT chip that has more MIPS and more HLL
support ---> then ... Lets use an embedded PC / Linux and write it in a higher level than C ---> then .... lets use a Full blown PC,
write it in VB / VB Net .. Java .. Flash .. yadda yadda ..... and suddenly a simple solution turns into a ridiculous mess.
I couldn't even count how many times I've been caught up in this scenario. THEN we have the repeated rumour how 8-bit is dead !
There's NO need ever for 8 bits, as 16/32 is as cheap. After all these years, I sure don't see 8 bit offerings disappearing.
Use whatever the FOOK you're happy with, and please try NOT to fuel these Nerd bitch wars that never seem to end.
Hello <tap> <tap> .. is this thing on?
 

Offline ptricks

  • Frequent Contributor
  • **
  • Posts: 670
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #8 on: April 30, 2013, 04:00:23 am »
For MCU you really should know assembly and should be able to understand what is going on internally on the chip, you can still program in other languages. Anyone who doesn't think assembly is relevant hasn't read any data sheets for MCU.
 

Offline marshallh

  • Supporter
  • ****
  • Posts: 1462
  • Country: us
    • retroactive
Re: Anyone else think assembly is (mostly) useless?
« Reply #9 on: April 30, 2013, 04:58:43 am »
No
Verilog tips
BGA soldering intro

11:37 <@ktemkin> c4757p: marshall has transcended communications media
11:37 <@ktemkin> He speaks protocols directly.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Anyone else think assembly is (mostly) useless?
« Reply #10 on: April 30, 2013, 05:08:14 am »
So, while I think it's very beneficial to know assembly, I have never found a place where it was necessary to use assembly in a real design.  i.e., most bottlenecks that you'll find in an embedded system have more to do with the architecture design and technology choices rather than that one damn piece of C code that won't run fast enough.

The answer is no, and you are just a stupid troll.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #11 on: April 30, 2013, 05:13:04 am »
The answer is no, and you are just a stupid troll.
Pot, meet kettle.
 

Online BravoV

  • Super Contributor
  • ***
  • Posts: 6276
  • Country: 00
Re: Anyone else think assembly is (mostly) useless?
« Reply #12 on: April 30, 2013, 05:25:31 am »
i.e., most bottlenecks that you'll find in an embedded system have more to do with the architecture design and technology choices rather than that one damn piece of C code that won't run fast enough.

Is there any chance even though very-very unlikely that the op never heard or understood the word called "bloatware" ?  :-//

Yeah, I'm pretty sure thats it.   ;D

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #13 on: April 30, 2013, 06:00:58 am »
C'mon folks, of course assembler is "mostly useless." No question.

Of all the gazillions of lines of code that have been written (by humans), how many are assembler? It's a tiny fraction of the total.

If you're hauling out the assembler to speed up some piece of code that's too slow in C, you're only going to beat a (decent) compiler in very specific situations. Your super-efficient assembly code probably has bugs (that you don't even realize) due to simplifying assumptions you've made. Before you get down to writing machine code, you should learn how to make C fast. Do you understand what pointer aliasing is? When should code be inlined? What about 'const' and 'volatile', ever used 'em?

Of course, if you're working with some craptastic architecture and a weak sauce compiler, you may be able to do a better job by hand.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2009
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #14 on: April 30, 2013, 07:31:04 am »
...you should learn how to make C fast 
...and how do you do that if you don't understand the underlying architecture and are well versed in asm?
 

Offline peter.mitchell

  • Super Contributor
  • ***
  • Posts: 1568
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #15 on: April 30, 2013, 07:58:21 am »
Bah, why would anyone want assembly when you can just lean the individual instruction sets and write everything in machine code.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 12051
  • Country: gb
    • Mike's Electric Stuff
Re: Anyone else think assembly is (mostly) useless?
« Reply #16 on: April 30, 2013, 08:20:45 am »
Having grown up on 6502 and later ARM code on BBC/Acorn platforms, followed by a lot of PIC work, it took me many years to accept that C compilers were worthwhile, but nowadays  I'd totally agree that it is rarely necessary to be able to write assembler these days, but it is very important to have enough understanding to be able to read it, so you can check what a compiler is generating, both for problem solving, debugging and analysing where efficiency can be improved.
Understanding assembly and the low-level hardware is the key to writing efficient code, especially with non-optimised compilers like GCC.

Once you know one or two instruction sets, minimal learning is needed to get enough understanding of a new architecture to follow code and get a feel for efficiency. The level of detail needed to write new assembler code is rarely necessary.


The only exception would be the very lowest end chips, and even there, it's only really essential for high volumes where you need to minimise cost by using the smallest possible chip (in terms of memory or peripherals)  - for lower volumes the additional cost of a bigger chip is a lower cost than the additional development cost.
 
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Corporate666

  • Supporter
  • ****
  • Posts: 2004
  • Country: us
  • Remember, you are unique, just like everybody else
Re: Anyone else think assembly is (mostly) useless?
« Reply #17 on: April 30, 2013, 08:27:05 am »
I think many engineers fall victim to wanting technical perfection without regards to time or cost, or the realities of business.  Not all, but many.  I've worked with engineers who will only use assembly because it's faster and more compact, and will happily spend much more time developing and debugging a program where the run speed or memory footprint were not important.

From that standpoint, C is very useful because you can much more quickly develop a project.

Having said that, I started off with x86 assembler about 20 or 25 years back, and while I grew to love it, I then grew to hate having to use it.  But it has a place... whether it's control over memory locations or execution speed or code compactness, there are times when nothing but assembler will do.

So no, I do not think it is mostly useless... but I do think that it's role has greatly diminished over the last decade or so, and it is sometimes overused needlessly.
It's not always the most popular person who gets the job done.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2009
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #18 on: April 30, 2013, 08:44:58 am »
The only exception would be the very lowest end chips, and even there, it's only really essential for high volumes where you need to minimise cost by using the smallest possible chip (in terms of memory or peripherals)  - for lower volumes the additional cost of a bigger chip is a lower cost than the additional development cost.
Having said what wrote earlier I have seen this very knowledgeable fellow over at microchip forum's (john temples) that has said that even for simple devices you can get good clean assembly out of C for very low end devices.

IIRC he had created some simple code in C that took in a serial stream and sent it out at a different rate and the assembly was as good as it gets.

However he knows all the C standards inside out and as such is aware of compiler limitations He also has a very good understanding of assembly.

I don't know that your average C coder without assembly knowledge and probably more importantly what the various tools in the compilation chain do to your source could have written code that efficiently

Edit: the low end mcu had no serial peripheral
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1623
  • Country: gb
Re: Anyone else think assembly is (mostly) useless?
« Reply #19 on: April 30, 2013, 08:47:02 am »
As a young engineer I remember going to a presentation by a large French organisation that were selling a simulation system that could work with anything that could be described by differential equations (e.g. electronic circuits as well as physical systems). It was a very big, and very expensive piece of software but what I remember most was it was all written in VAX assembler! Now the VAX is no more presumably that monumental human effort is now defunct.

c was invented to replace assembler in writing OSs in particular so it is very close to assembler (with all the bit manipulation and the ease in which you can store different types in the same memory space) so for most systems it makes sense to write the bulk of them in a high level language like c.

But assembler is not useless, you actually know what is happening with assembler as well as it being faster, for example in one project I was doing I was using a bit field in c to store flags. One of my values was 2 bits and it was unsigned so I wanted to store the numbers 0,1,2 or 3. I found that when I put a 3 in (and I had declared it to be unsigned) it still failed the test for equality with 3. The reason was it was treating the binary 11 as 2s compliment and expanding it up to be -1 when doing the test.

Personally on something like an embedded system I'd have thought that the I/O and very time dependant stuff might best be done in assembler while things like FFTs are probably best programmed in c.
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Anyone else think assembly is (mostly) useless?
« Reply #20 on: April 30, 2013, 09:25:57 am »
While fully aware that this is a never ending story, allow me to deposit my 2 cents.

A personal level observation is that as in any endeavour, also in SW engineering there are fundamentally different kinds of people involved. Experience of course is one thing and it may explain some of the opinions (it is exciting to some to be able to control every aspect of a processor on the minutest detail level. It also usually gets old after a while). But that aside, the Gaussian curve rules. At one end are the control freaks who simply must know everything or the world collapses. The opposing end is populated by the laissez-faire posse who coudn't give a s**t what happens inside, only that their software runs as specified on the high level. The rest of us find our places somewhere in the middle.
What i am trying to say is that use or otherwise, of assembly is not primarily a technical issue, but an attitude. At least where the ends of the bell curve are concerned. Yes there are valid (technical) reasons for using assembly, but less than the most diehard advocates let us understand. The majority of "standard" cases where assembly would be needed tend to be included in architecture specific constructs embedded in this or that library or header. So while technically expressed in assembly, in practice a part of the toolchain environment. In my book that does not count as programming in assembler any more than printing the compiler generated assembly does.

I have started programming embedded systems when Intel 8080 and heaven forbid, 8008 were newish or at least relevant chips and PL/M was supposed to be a "high-level" language. Ever since, i have needed assembly in implementing the few kernel functions in RTOS:es where you just have to manipulate the stack directly. Even that could conceivably be done in C but not without calisthenics making assembly the easier choice. Other than that the only items that come to mind are interfacing an ancient AMD 9511 coprocessor and even that would have been doable in PL/M (or C for that matter).

As so many have noted already there is a valid reason for using assembler to solve a specific requirement for program speed or size. At the same time i have seen numerous cases where the most cunning assembly algorithm was ultimately futile because optimization will only get you so far and in the end you have to look for fundamentally different solutions. Of course there are special cases where a hand crafted algorithm can speed a loop an order of magnitude or more and then assembly is warranted. It just seems that such cases are getting increasingly rare.

As to the claim that knowing assembler is good because you can then verify that the compiler is doing its job - i disagree. Sure, one can possibly learn the architecture of a specific chip well enough to be able to do that but then that knowledge is associated with that particular chip. Change architectures and the knowledge is, if not worthless at least worth significantly less. In my opinion this argument is fundamentally flawed because nobody a) checks a large application like this anyway, b) trying to guess which parts to spot check - you will eventually guess wrong and c) if it really is important, there are numerous profiling tools made expressly for this purpose. Those make short work of finding out where the execution flow spends its time. Regarding a) and b), who actually cares how the generated assembly looks like if it does the job correctly and is fast enough? Also, try to follow on the assembly level C/C++ code optimized to the max and i promise you'll sprain your brain.

Having said all this, i also want to say that i am not a die hard opponent of assembly. Just that many if not most of the pro arguments i hear are the flawed ones that i rant against above. All the real arguments are mostly against using assembly: maintainability, productivity, portability, testability.
Maybe i am just too lazy or too far in the bell curve to care but my projects seem to do quite well without a line of assy involved. YMMV.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline JuKu

  • Frequent Contributor
  • **
  • Posts: 566
  • Country: fi
    • LitePlacer - The Low Cost DIY Pick and Place Machine
Re: Anyone else think assembly is (mostly) useless?
« Reply #21 on: April 30, 2013, 09:26:55 am »
No, it is not useless. You really need it:
- To learn how microcontrollers (and real computers, but to lesser extent) really work and what they really are doing
- To learn why you don't want to use it, unless you really have to
- To write compilers and OS kernels
- When you need sub-microsecond jitter or response time in few microseconds in your interrupts (but more often than not, you are doing it wrong)
- When it makes economical sense to use a chip that is 10c cheaper and the application is very simple (but you still might be doing it wrong, although not as often as in the previous case)
- You are forced to update a very old system (but then, you are doing it wrong) or one that was done wrong to begin with
- In a hobbyist cases, when you can't afford to do it right

And yes, it is mostly useless in real world, where productivity and reliability counts.

[ I build real time embedded systems for living. As a rough estimate, I would say that the ratio assembler vs high level language is 1 to 100000. But I don't write OS kernels, I just use them. At design time, the estimated quantities are in thousands (not in hundreds of thousands, that would change the equation!). So, a chip costing 1€ more is ok, if it saves a month in engineering. And a month is not much at all amortized over design, development, testing and maintenance. And 1-2€ buys a lot today: That's a difference of a tiny 4 or 8 bit micro and powerful 32 bit. It also pays for a dedicated peripheral controller or FPGA. YMMV, but assembler is hardly used in real life, in my work, practically never.

When I hire microcontroller engineers, I would not hire somebody who doesn't know assembler, nor would I hire somebody who prefers to use assembler. ]
http://www.liteplacer.com - The Low Cost DIY Pick and Place Machine
 

Offline blewisjr

  • Frequent Contributor
  • **
  • Posts: 301
Re: Anyone else think assembly is (mostly) useless?
« Reply #22 on: April 30, 2013, 10:03:29 am »
I found this discussion rather interesting so I felt I would chime in.  First and foremost I agree that the uses of assembler in modern times is relatively moot considering how smart C compilers have become.  Outside of a few small cases like others have stated you can save yourself tons of time and bugs using C.  But despite all this I have been using assembler.  I am new to micro controllers in general and even new to assembler.  I have programmed in C for nearly 20 years now but I am using assembler on my AVR's and PIC's.  Why you ask?  It is quite simple personal preference.  1. I have always wanted to learn assembler.  2. I always like to learn something new if I am not learning it is not worth doing.  3. I enjoy assembler, no crazy convoluted abstractions just up and straight do this. 4. I enjoy the challenge in trying to figure out how to do something that could be just 3 lines of code in C.  It is a new thought process and over all it is making me a much better developer even from the C side.

So over all I think it is worth learning and using assembler at least until the buzz wears off the knowledge gained is valuable.
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 6541
Re: Anyone else think assembly is (mostly) useless?
« Reply #23 on: April 30, 2013, 10:50:29 am »
No, Asm is not useless although it might not be the default go-to for most tasks now. Not only optimising, but when debugging, it's important to be able to figure out what the compiler's generated and wht it's doing. The strength of HLLs lies in their conciseness and ability to generate large amounts of code quickly; quality-quantity tradeoff. At the same time the abstraction can limit what the programmer wants to express and optimise, because the compiler mostly has to follow the language standard and doesn't know of the assumptions the programmer had in mind.
 

Offline nuhamind2

  • Regular Contributor
  • *
  • Posts: 138
  • Country: id
Re: Anyone else think assembly is (mostly) useless?
« Reply #24 on: April 30, 2013, 11:35:12 am »
What about peripheral. Microcontroller is not just about the core right. Like Timer, what if I set this register like this, what if I set that register like that ,what If I want to divide clock by some value, what if I want to compare match happen at some value. Aren't we actually studying the 'assembly' of that peripheral  :-//
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf