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

0 Members and 1 Guest are viewing this topic.

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #25 on: April 30, 2013, 11:44:10 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  :-//
No. What we are studying is the peripherals register set and their addresses are usually defined in the MCU's include file. I often find it quicker and easier to read the data sheet and understand the registers than trying to decrypt the mcu vendor's library functions
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13726
  • Country: gb
    • Mike's Electric Stuff
Re: Anyone else think assembly is (mostly) useless?
« Reply #26 on: April 30, 2013, 11:48:30 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.


Yes, but at this level you need to regard the C compiler as little more than a macro-assembler and keep a tight eye on the output.
The differences between C and assembly become less significant at this level, and sometimes assembly has some advantages in terms of things like optimising register usage on register-rich architectures like AVR and ARM, and making full use of status bits etc.
A good example of the 'macro assembler' approach is using carry bits after a shift operation, which C does not support very efficiently. e.g.on the PIC :
reg<<=1;
if (CARRY) .....;  // use hardware carry flag because you know what the compiler did with the previous instruction

 
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline nuhamind2

  • Regular Contributor
  • *
  • Posts: 138
  • Country: id
Re: Anyone else think assembly is (mostly) useless?
« Reply #27 on: April 30, 2013, 11:56:56 am »
No. What we are studying is the peripherals register set and their addresses are usually defined in the MCU's include file.
What I mean is we still need to learn low level aspect of microcontroller.
I often find it quicker and easier to read the data sheet and understand the registers than trying to decrypt the mcu vendor's library functions
I agree
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1771
  • Country: gb
Re: Anyone else think assembly is (mostly) useless?
« Reply #28 on: April 30, 2013, 12:39:17 pm »
It is going a little off topic, but when I first learnt c it was closer to being like assembler. In particular there was the register type which you could use to tell the compiler which integers you wanted stored in registers instead of on the stack. But compilers now just ignore such directives as they know better how to do optimising of registers.

I used to like the BBC Micro Basic approach of having an in-line assembler.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13726
  • Country: gb
    • Mike's Electric Stuff
Re: Anyone else think assembly is (mostly) useless?
« Reply #29 on: April 30, 2013, 03:14:46 pm »
It is going a little off topic, but when I first learnt c it was closer to being like assembler. In particular there was the register type which you could use to tell the compiler which integers you wanted stored in registers instead of on the stack. But compilers now just ignore such directives as they know better how to do optimising of registers.
It can't always know what you want - for example you may want to dedicate some registers for use by an interrupt task to reduce context save/restore time. The IAR compiler allows this by specifying variables to be in a specific register - not sure if it pays attention to the register qualifier
 
Quote
I used to like the BBC Micro Basic approach of having an in-line assembler.
Absolutely - it was the ultimate macro-assembler!
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1771
  • Country: gb
Re: Anyone else think assembly is (mostly) useless?
« Reply #30 on: April 30, 2013, 03:19:20 pm »
to quote from Real Programmers Don't Use PASCAL,

"If you can't do it in FORTRAN, do it in assembly language. If you can't do it in assembly language, it isn't worth doing."


http://www.ee.ryerson.ca/~elf/hack/realmen.html
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Anyone else think assembly is (mostly) useless?
« Reply #31 on: April 30, 2013, 03:25:09 pm »
The answer is no, and you are just a stupid troll.

+1 on the troll bit, can we have a thread about verilog vs. VHDL, about C vs. C++, about Microchip vs. Atmel?
 

Offline croberts

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #32 on: April 30, 2013, 03:38:02 pm »
All designs are contextual. If assembly language was useless (to me) the network and control system for my whole house solar powered LED lighting system would not be functioning. Designers should use whatever programming language they feel is appropriate for the project they are doing and perhaps equally important that they feel comfortable and confident using.
 

Offline kfitch42

  • Frequent Contributor
  • **
  • Posts: 300
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #33 on: April 30, 2013, 03:39:08 pm »
To summarize the discussion so far:
1) It is always important to understand the layer below you. If writing C, understand (but not necessarily use) assembly. If using assembly understand CPU/system architectures... ( on a related note you should also understand the layer above...)
2) When push comes to shove, hand optimization of assembly is sometimes necessary (for throughput/latency/size...).
3) Compilers/kernels/BSPs(board support packages) don't materialize out of thin air. Someone somewhere wrote some assembly (possibly gcc inline assembly) to initialize the chip in the right mode. And someone else wrote the code that takes your C and turns it into assembly. Sure hope that guy knew assembly :)
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #34 on: April 30, 2013, 04:26:15 pm »
1) It is always important to understand the layer below you...
+1
I can't think of many engineering disciplines that don't require you to know the fundamentals, you may not need them but you should still know them.

Sometimes if you are doing tricky shit the only way to access some of the core stuff is with inline assembly, namely because that core stuff is used by the compiler and it wont give you access to it. In this case not only do you need to know asm you also need to know the compiler and the subsystem it creates to manage and run your code.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26872
  • Country: nl
    • NCT Developments
Re: Anyone else think assembly is (mostly) useless?
« Reply #35 on: April 30, 2013, 07:22:43 pm »
To summarize the discussion so far:
1) It is always important to understand the layer below you. If writing C, understand (but not necessarily use) assembly. If using assembly understand CPU/system architectures... ( on a related note you should also understand the layer above...)
2) When push comes to shove, hand optimization of assembly is sometimes necessary (for throughput/latency/size...).
3) Compilers/kernels/BSPs(board support packages) don't materialize out of thin air. Someone somewhere wrote some assembly (possibly gcc inline assembly) to initialize the chip in the right mode. And someone else wrote the code that takes your C and turns it into assembly. Sure hope that guy knew assembly :)
These are only valid if you need to interact with low level CPU stuff. Lots of software doesn't need that. In fact most software engineers have no clue about what is going on exactly but are still very capable of delivering a good piece of software. Being able to write better assembly than a C compiler is a myth unless the compiler is extremely crappy. Most compilers are made by very competent people who know how to get the best performance or code size. The last time I used inline assembly (one line) was to get the stack pointer in a fault handler for a Cortex Mx microcontroller. That is the only assembly you may need on a Cortex Mx controller. They can start a C program without needing any assembly to setup a stack pointer etc.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Anyone else think assembly is (mostly) useless?
« Reply #36 on: April 30, 2013, 07:32:04 pm »
These are only valid if you need to interact with low level CPU stuff. Lots of software doesn't need that. In fact most software engineers have no clue about what is going on exactly but are still very capable of delivering a good piece of software.

From a practical point of view, you are absolutely correct. Still, a programmer who doesn't know what a stack pointer is is just sad. Maybe it doesn't say anything about their ability to deliver correct software, but it sure as hell speaks volumes about their interest in the subject, and I'd worry about the quality of something designed by an engineer who's not interested in what he does.

Personally I think that being of the mindset required to actually try to avoid learning something is indicative of a severe lack of passion.
« Last Edit: April 30, 2013, 07:34:23 pm by c4757p »
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #37 on: April 30, 2013, 07:52:49 pm »
The last time I used inline assembly (one line) was to get the stack pointer in a fault handler for a Cortex Mx microcontroller. That is the only assembly you may need on a Cortex Mx controller.
Inline assembler is pretty handy when you need it. Of course, you have to understand what the compiler is going to do with the few lines of assembler. GCC has some pretty neat stuff for specifying where the assembler operands come from.

One thing that rubs me the wrong way in the mcu world is OEMs who ship code in assembler when it could easily be in C. Initialization of static variables (i.e., the code that runs before main()) is a classic example. This is easily done in C, and much more understandable that way compared to its assembly equivalent.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Anyone else think assembly is (mostly) useless?
« Reply #38 on: April 30, 2013, 07:55:56 pm »
One thing that rubs me the wrong way in the mcu world is OEMs who ship code in assembler when it could easily be in C. Initialization of static variables (i.e., the code that runs before main()) is a classic example. This is easily done in C, and much more understandable that way compared to its assembly equivalent.

Reading it is a good way to get a feel for the optimal way to write that sort of stuff in assembly for that specific MCU. Assembly can definitely be a "write-only" language, but in my experience the example code is usually written well enough that you can read it easily.
No longer active here - try the IRC channel if you just can't be without me :)
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26872
  • Country: nl
    • NCT Developments
Re: Anyone else think assembly is (mostly) useless?
« Reply #39 on: April 30, 2013, 08:23:00 pm »
These are only valid if you need to interact with low level CPU stuff. Lots of software doesn't need that. In fact most software engineers have no clue about what is going on exactly but are still very capable of delivering a good piece of software.

From a practical point of view, you are absolutely correct. Still, a programmer who doesn't know what a stack pointer is is just sad. Maybe it doesn't say anything about their ability to deliver correct software, but it sure as hell speaks volumes about their interest in the subject, and I'd worry about the quality of something designed by an engineer who's not interested in what he does.

Personally I think that being of the mindset required to actually try to avoid learning something is indicative of a severe lack of passion.
I strongly disagree. Its all about focussing on what is relevant and what is not. In C and C++ you have to worry about pointers and dynamic allocation. In languages like PHP, Java and Lua you don't have to worry about those. This means you can spend more energy on creating great new software instead of being held back by having to deal with the low level stuff. Taking technology for granted and using existing technology as bricks (black boxes) to create new software is the way technology moves forward.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline marmad

  • Super Contributor
  • ***
  • Posts: 2979
  • Country: aq
    • DaysAlive
Re: Anyone else think assembly is (mostly) useless?
« Reply #40 on: April 30, 2013, 08:41:33 pm »
I strongly disagree. Its all about focussing on what is relevant and what is not. In C and C++ you have to worry about pointers and dynamic allocation. In languages like PHP, Java and Lua you don't have to worry about those. This means you can spend more energy on creating great new software instead of being held back by having to deal with the low level stuff. Taking technology for granted and using existing technology as bricks (black boxes) to create new software is the way technology moves forward.

Sometimes technology moves forward because someone steps backwards and takes apart one of the black boxes - and then recreates it in a much more efficient, innovative, or easy to use way. If you think progress only comes from using tools which someone else - with their own set of misconceptions and vertical thinking - developed, you're badly mistaken.
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1771
  • Country: gb
Re: Anyone else think assembly is (mostly) useless?
« Reply #41 on: April 30, 2013, 09:02:20 pm »
The best computer language to use depends on what you're doing - that is why there are so many of them (languages).

I program in SML (a functional programming language) and in C most of the time. SML is statically typed and is very good for anything involving pattern matching. It is very robust which arises from its origins in Logic and Theorem Proving. But when it comes to code that interfaces more directly with hardware it obviously makes more sense to use a language such as C or assembler even.
Sometimes you want to write code that is independent of hardware and sometimes you want to do the opposite, most programmers/engineers should have the interest to find out about both approaches. Most of the time I don't want to know if integers are stored big-endian or little-endian for example but it might be dangerous not to even know that there are differences between various processors.

It is odd, but computer languages like operating systems seems to inspire people with almost religious zeal.
 

Offline jmoleTopic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: us
    • My Portfolio
Re: Anyone else think assembly is (mostly) useless?
« Reply #42 on: April 30, 2013, 09:07:10 pm »
My point is, writing some assembly is not necessarily the answer to speeding up your slow-ass program. You need to have a good knowledge of the system you're working with, the execution pipeline, and the alternative solutions, before you can make an informed decision on whether or not you really need to use asm to speed up some time-critical loop (or ISR, or whatever).

 

Offline ben_r_

  • Frequent Contributor
  • **
  • Posts: 419
  • Country: us
  • A Real Nowhere Man
Re: Anyone else think assembly is (mostly) useless?
« Reply #43 on: April 30, 2013, 10:27:03 pm »
Huh, thats funny, I personally ONLY use assembly when working with MCUs (PICs). I actually do not like higher level languages for them and prefer to have complete control and understanding of whats being done. But I know for many learning assembly is like how most people feel about learning math. For me it was just made more sense and thus came easy.
If at first you don't succeed, redefine success!
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Anyone else think assembly is (mostly) useless?
« Reply #44 on: April 30, 2013, 10:39:41 pm »
Yeah, I've never thought of assembly as difficult or tedious for low-level "microcontroller-y" tasks. I wouldn't try to write a word processor in it, but it's always seemed to be about an equal choice for microcontroller stuff. Really, most of the functions you call and statements you write end up being just a shove or two into a register on a microcontroller.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Anyone else think assembly is (mostly) useless?
« Reply #45 on: May 01, 2013, 12:11:31 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.

that may be, but realise this : anytime the computer starts , it is a chunk of assembly that finds and initializes all peripherals , goes to seek the bootsector , loads the assembly program that is stored there and then loads to Os.
Without assembly your machine would not boot...

C is handy dandy except if you have a freshly reset cpu where the memory controller is not initialized so you have no stack , no ram no nothing and you need to bring it up .... good luck doing it in 'c' ... ( there are bioses that are mainly written in 'c' but the real startup code, the first few hundred bytes of code the set the machine in the right mode are handwritten assembly.

so don't dis it...

Besides speed and size there are other situation. situations so critical you simply don't trust a compiler ! just moving a block of code may cause the compiler to create completely different code . simply because it now walks a different optimizer pathway.
sometimes compilers are bloody annoying like when they 'optimize' a block of code away because it is never called... or that's what it thinks... what if there are instance where the cptr and dptr are manipulated outside the scope to call that function directly.

in that case you write some stuff as inline assembler and tell the compiler : hands off.

other cases are where a new core is available but the compiler has no support for a specific feature yet.... like a core that all of a asudden has extra interrupt vectors. at least then you can throw in an 'org xxx' to offset code generation and write some hooks in assembly to patch in the unsupported stuff until the compiler builders can catch up.

an extreme case is to provide patching code... a chunk of silicon has a hardware bug. at boot a chunk of assembly is called that circumvents the normal startup , patches the core and then the compiler can go off.. i know several cpu's ( Arm7 based) that have such problems. the assembly code sets the registers right so a normal program can run
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline croberts

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #46 on: May 01, 2013, 12:28:39 am »
Assembly language is just that...a programming language. This is not the first time I have observed a topic disparaging it. Assembly language is no threat to the favorite flavor of high level language so a more interesting question is why an attempt to declare it "useless" by consensus? To paraphrase the line from Shakespeare's Hamlet "The forum doth protest too much, methinks."
 

Offline kt315

  • Regular Contributor
  • *
  • Posts: 51
Re: Anyone else think assembly is (mostly) useless?
« Reply #47 on: May 01, 2013, 02:40:25 am »
 
  If you can avoid using assembler you should by all means do it. There are case when you cannot, but it happens way less often than some of the comments above may imply.

  People have not come up with a better way to deal with complexity so far other than raising the level of abstraction. We program FPGA in verilog and VHDL and do not worry too much if the compiler is not going to use efficiently every single logic gate. We sure could draw a hardware like schematic for every FPGA system, could not we?

  While we are talking about a hobby, your time is essentially free (you are not working -- you are having fun, at least that is the idea).

  I wish all the best to anyone implementing TCP/IP protocol in assembly (if you are up for the challenge, shoot for a web server).

  Modern embedded systems has millions of lines of code (android is a great example), and even programming chips like pic32 would be way too expensive in assembly language alone.
 
  It is not about assembly vs C, it is about picking up the right tool for the job. And if the only tool you have is a hammer -- all the problems look like nails.

  You will move way faster if you can use a higher level language, until you run into hardware limitations that is; and  even then, you might need just a tiny bit of assembly, which should be in a separate module anyway.
 
  If the only language you recognize is assembly -- try learning C, you will find a lot of way more efficient ways (implementation time wise) doing things.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #48 on: May 01, 2013, 04:53:46 am »
that may be, but realise this : anytime the computer starts , it is a chunk of assembly that finds and initializes all peripherals , goes to seek the bootsector , loads the assembly program that is stored there and then loads to Os.
Without assembly your machine would not boot...
ARM Cortex-M3 will boot just fine without assembly. The first word of your reset vector is the stack pointer, and the second is the reset handler. They're just addresses--no opcodes involved, and hence, "no assembly required."
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9925
  • Country: nz
Re: Anyone else think assembly is (mostly) useless?
« Reply #49 on: May 01, 2013, 05:01:52 am »
Micrcontroller assembly is for when management refuse to do the project properly and want a cheap 'patch job' instead. ;D
- More code needed in an already full micro.
- More speed from existing micro instead of using a newer/faster one.
- Substandard micro selected for the job due to price.

For more advanced stuff, like PC's or phones, where you have 3rd party apps, assembler is useful to get an edge over your compeditors by having a faster app on the same hardware.
- Faster framerates in PC games
- Quicker image manipulation routines
« Last Edit: May 01, 2013, 05:10:02 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf