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

0 Members and 1 Guest are viewing this topic.

Online Marco

  • Super Contributor
  • ***
  • Posts: 6694
  • Country: nl
Re: Anyone else think assembly is (mostly) useless?
« Reply #100 on: May 11, 2013, 03:26:18 pm »
People creating high performance code generally build a mental model of the compiler by looking at the disassembled code, need to know assembler for that.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26752
  • Country: nl
    • NCT Developments
Re: Anyone else think assembly is (mostly) useless?
« Reply #101 on: May 11, 2013, 05:35:53 pm »
One thing about ASM is if you really understand it well you can pull off some amazing things with little resources. This is a pc OS written completely in ASM and is under 1.44MB.  Sure we don't have to worry about such low resources now, but as a proof of concept it is cool.
You can do exactly the same with C. These kind of (waste of time) projects keep feeding the myth that assembly is the way to write fast and small programs.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #102 on: May 11, 2013, 11:04:38 pm »
No matter how good your C coding skills are the initializer (standard routine that gets added to the beginning of the code to initialize statics and friends) takes some space, around 100 bytes for Microchip C compiler.  I'm currently coding in assembly for tiny 256B ROM 16B RAM part for this very reason - next size memory size part is 10c more expensive and client is willing to pay for developing assembly code to save money in production.
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Anyone else think assembly is (mostly) useless?
« Reply #103 on: May 12, 2013, 12:16:56 am »
No matter how good your C coding skills are the initializer (standard routine that gets added to the beginning of the code to initialize statics and friends) takes some space, around 100 bytes for Microchip C compiler.

The timer example for a PIC12F1822 which I posted elsewhere compiles with Microchip XC8 to 75 instructions total. The 'initializer' consists of 3 gotos 2 file register clears and a bank select.

A minimal C program for a PIC10F200 compiles to 6 instructions.
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #104 on: May 12, 2013, 02:36:28 am »
Examples like that only prove that small C programs can in fact be produced. They won't prove that useful small C programs can be produced. In my experience (producing useful small programs), writing a C program for execution on a machine with limited resources often results in assembly program written in C syntax - no stack, no local scopes, minimal structure, etc.. Many times I found that writing such program in assembly makes it easier to code/maintain.
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Anyone else think assembly is (mostly) useless?
« Reply #105 on: May 12, 2013, 02:55:24 am »
Examples like that only prove that small C programs can in fact be produced.

It proves that your claim that

Quote
the initializer (standard routine that gets added to the beginning of the code to initialize statics and friends) takes some space, around 100 bytes for Microchip C compiler.

Is crap - I was just being more polite about it first time round.
 

Offline BravoV

  • Super Contributor
  • ***
  • Posts: 7547
  • Country: 00
  • +++ ATH1
Re: Anyone else think assembly is (mostly) useless?
« Reply #106 on: May 12, 2013, 03:12:42 am »
In my view, it is human nature.  Things that takes a lot of effort and energy to master become a great investment.  With great investment comes a protective sentiment to protect the time and energy you have invested.  Who would like to think of themselves as fools having spend years of their life learning something useless or of little value.  Conversely, simple to learn stuff requires merely little investment or none will earned small or no loyalty.  You wont found as much energetic defender of say which font when printed is nicer to look at while we all have our preferences.

Rick

Personal experience is major factor imo, like the OP which started his 1st mcu world using arduino, and then moved to GUI thingy "click & drag programming" using mouse with no or much less typing needed, hence appreciation on assembly language is obvious.

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #107 on: May 12, 2013, 03:15:01 am »
Quote
No matter how good your C coding skills are the initializer (standard routine that gets added to the beginning of the code to initialize statics and friends) takes some space, around 100 bytes for Microchip C compiler.
A good C compiler will let you omit that.  "Optiboot", the bootloader for Arduino Uno, is under 512 bytes and written almost entirely in C.  Suppressing the normal C startup code (and the rather large vector table that it includes) is a major part of that.

Quote
a pc OS written completely in ASM and is under 1.44MB.
1) 1.44MB is  pretty large.  The original Mac had 128k of RAM...
2) You shouldn't assume that it's "under 1.44MB" just because it fits  on a single floppy.  There are substantially useful versions of linux that fit on a single floppy, but they work by decompressing a filesystem into ramdisk.
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #108 on: May 12, 2013, 03:50:02 am »
Quote
"Optiboot", the bootloader for Arduino Uno, is under 512 bytes and written almost entirely in C.

Is it this optiboot -> https://code.google.com/p/optiboot/source/browse/#hg%2Foptiboot%2Fbootloaders%2Foptiboot ? If yes, then this is a good example of asm program in c syntax. The main loop ( https://code.google.com/p/optiboot/source/browse/optiboot/bootloaders/optiboot/optiboot.c#472 ) is more than 150 lines long, the structure is kept as flat as possible, etc.. Also, just for fun, take a look inside boot.h

Back in the days we were joking "you can write FORTRAN programs in any language". Certainly, no one knows what a FORTRAN is anymore but still - if your application requires structure of assembly language program, code it in assembly language.
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #109 on: May 12, 2013, 04:20:43 am »
...
Back in the days we were joking "you can write FORTRAN programs in any language". Certainly, no one knows what a FORTRAN is anymore but still - if your application requires structure of assembly language program, code it in assembly language.

No joke, I saw an ad for a FORTRAN programmer back about 2 or perhaps 3 months ago.  I didn't look at the details.

 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #110 on: May 12, 2013, 04:22:10 am »
Quote
No joke, I saw an ad for a FORTRAN programmer back about 2 or perhaps 3 months ago.  I didn't look at the details.

What kind of rate were they offering?
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline Fsck

  • Super Contributor
  • ***
  • Posts: 1157
  • Country: ca
  • sleep deprived
Re: Anyone else think assembly is (mostly) useless?
« Reply #111 on: May 12, 2013, 04:23:14 am »
...
Back in the days we were joking "you can write FORTRAN programs in any language". Certainly, no one knows what a FORTRAN is anymore but still - if your application requires structure of assembly language program, code it in assembly language.

No joke, I saw an ad for a FORTRAN programmer back about 2 or perhaps 3 months ago.  I didn't look at the details.

If you're a scientist, fortran and pascal are still common. ;)
"This is a one line proof...if we start sufficiently far to the left."
 

Offline Bloch

  • Supporter
  • ****
  • Posts: 453
  • Country: dk
Re: Anyone else think assembly is (mostly) useless?
« Reply #112 on: May 12, 2013, 05:47:14 am »
If you're a scientist, fortran and pascal are still common. ;)


Or in the  Automation, it is hidden in IEC 61131-3 standard. Pascal are a much better than c for many things.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #113 on: May 12, 2013, 06:15:52 am »
Quote
No joke, I saw an ad for a FORTRAN programmer back about 2 or perhaps 3 months ago.  I didn't look at the details.

What kind of rate were they offering?

I really don't know.  I did not look at the details.  I was curious enough to checked it to see if it was for real, and it was.  That was the only thing I checked.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #114 on: May 12, 2013, 07:08:21 am »
Quote
Is it this optiboot -> https://code.google.com/p/optiboot
Yep.

Quote
If yes, then this is a good example of asm program in c syntax.

I won't disagree.  It's a big case statement (except that if/else turns out to be slightly smaller) that implements a bunch of rather simple commands, so it wouldn't benefit a lot from the use of C "features."  In fact, one advantage of coding it in real ASM might have been the ability to make the source layout more modularly grouped in spite of having nearly exactly the same structure.

Quote
just for fun, take a look inside boot.h
(which contains a bunch of inline assembler for implementing various pieces of "self-programming" functionality.)  Yep; exactly the sort of thing you need assembler for.  Note that most of this is not used at all by the bootloader, and all of it is a slightly-modified version of a file from avr-libc that is normally provided with the compiler.   There are several other strategic bits of inline assembler that I think are reasonable examples of cases where (inline) assembler makes sense.

All of which has little to do with the point I was making that being coded in C did NOT automatically cause 100+ bytes of startup code to get included.  Or any other overhead, for that matter.

(BTW, I made a significant effort to see if I could hit the next-smaller bootloader size (256 bytes) by recoding the C in careful assembler.  I pretty-much convinced myself that it's not possible.  I MIGHT get a 256byte serial bootloader if I simplified the protocol, but that's a different solution.)
 

Offline nuhamind2

  • Regular Contributor
  • *
  • Posts: 138
  • Country: id
Re: Anyone else think assembly is (mostly) useless?
« Reply #115 on: May 12, 2013, 11:55:35 am »
I also think everything I learn in uni is mostly useless.
 

Offline Bloch

  • Supporter
  • ****
  • Posts: 453
  • Country: dk
Re: Anyone else think assembly is (mostly) useless?
« Reply #116 on: May 12, 2013, 12:37:53 pm »
I also think everything I learn in uni is mostly useless.
Do you learn c in uni ?
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26752
  • Country: nl
    • NCT Developments
Re: Anyone else think assembly is (mostly) useless?
« Reply #117 on: May 12, 2013, 12:54:16 pm »
Quote
"Optiboot", the bootloader for Arduino Uno, is under 512 bytes and written almost entirely in C.

Is it this optiboot -> https://code.google.com/p/optiboot/source/browse/#hg%2Foptiboot%2Fbootloaders%2Foptiboot ? If yes, then this is a good example of asm program in c syntax. The main loop ( https://code.google.com/p/optiboot/source/browse/optiboot/bootloaders/optiboot/optiboot.c#472 ) is more than 150 lines long, the structure is kept as flat as possible, etc.. Also, just for fun, take a look inside boot.h
Sorry but the point you are trying to make simply is not there... The C source is easy to read and porting it over to another microcontroller shouldn't be hard. Functions which do something with received data always look this way. Perhaps the author should have used a switch instead of if-else-if-else.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline nuhamind2

  • Regular Contributor
  • *
  • Posts: 138
  • Country: id
Re: Anyone else think assembly is (mostly) useless?
« Reply #118 on: May 12, 2013, 01:04:15 pm »
I also think everything I learn in uni is mostly useless.
Do you learn c in uni ?
Yes
 

Offline Baliszoft

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: hu
Re: Anyone else think assembly is (mostly) useless?
« Reply #119 on: May 12, 2013, 01:16:49 pm »
"Anyone else think assembly is (mostly) useless?"

No. Assembly rules forever! :D
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #120 on: May 12, 2013, 08:05:46 pm »
Quote
Do you learn c in uni ?
Nah.  PL/1, Fortran, Pascal, and Assembler.  And some APL.
(Hmm.  Of those, the assembler is more akin to the assemblers I use now than any of the other languages are similar to the C/C++/Java/Perl/etc that are popular HLLs today...  An odd thought.)
 

Offline SolarSunrise

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ua
  • Hi there!
Re: Anyone else think assembly is (mostly) useless?
« Reply #121 on: May 14, 2013, 07:20:12 pm »
I mostly program in Assembly to understand the system architecture (I program a 32 bit 168Mhz ARM Cortex M4 in Assembly. It's the best way to get friendly with your complex micro-friend  :)).

Also, it comes in handy when you are doing DSP's and other real time processing. But C can do as good as assembly if you code efficiently.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Anyone else think assembly is (mostly) useless?
« Reply #122 on: May 15, 2013, 12:52:08 am »
Quote
C can do as good as assembly if you code efficiently.
Also, the reverse: "Assembly language can be as bad as C code if you DO NOT code efficiently."
This is a pretty key point; programming well in assembly is more difficult than programming well in a HLL.  Especially if you're trying to keep it up over all of 100k of object code.  Or 30k.  That pic10f with 512 instruction words; not as much of a problem...
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1289
  • Country: fi
Re: Anyone else think assembly is (mostly) useless?
« Reply #123 on: May 15, 2013, 06:44:10 am »
Quote
C can do as good as assembly if you code efficiently.
Also, the reverse: "Assembly language can be as bad as C code if you DO NOT code efficiently."
This is a pretty key point; programming well in assembly is more difficult than programming well in a HLL.  Especially if you're trying to keep it up over all of 100k of object code.  Or 30k.  That pic10f with 512 instruction words; not as much of a problem...
I think there is a point here: Debating whether to code for a 512 byt program space in asm or C or some other HLL is essentially fruitless. Whatever your choice you won't have much of a structure or complexity in such a miniscule space.
Conversely, the logic of choice in such a small environment and the logic of choice for a much larger environment are 2 different things and should not be approached equally. You can easily walk to the corner store but a holiday trip to Thailand (Hawaii for the yanks) means an airplane ticket. Same thing.
 
Nothing sings like a kilovolt.
Dr W. Bishop
 

Online AlfBaz

  • Super Contributor
  • ***
  • Posts: 2183
  • Country: au
Re: Anyone else think assembly is (mostly) useless?
« Reply #124 on: May 15, 2013, 09:16:20 am »
Quote
C can do as good as assembly if you code efficiently.
Also, the reverse: "Assembly language can be as bad as C code if you DO NOT code efficiently."
This is a pretty key point; programming well in assembly is more difficult than programming well in a HLL.  Especially if you're trying to keep it up over all of 100k of object code.  Or 30k.  That pic10f with 512 instruction words; not as much of a problem...
I think there is a point here: Debating whether to code for a 512 byt program space in asm or C or some other HLL is essentially fruitless. Whatever your choice you won't have much of a structure or complexity in such a miniscule space.
Conversely, the logic of choice in such a small environment and the logic of choice for a much larger environment are 2 different things and should not be approached equally. You can easily walk to the corner store but a holiday trip to Thailand (Hawaii for the yanks) means an airplane ticket. Same thing.
I think you've hit the nail on the head here.
It seems it has more to do with the definition of embedded or more precisely the perspective one takes when considering an "embedded project".

Given that some MCU's these day's have resources equivalent to or even exceeding PC's of about 10 years ago it becomes very inefficient to consider not only low level languages but the software platforms on which they are built.

Some small 8 bit architectures are not designed with C in mind and C compilers written for these things generally produce horrible convoluted output, namely because the big players don't put in any significant development into a compiler that isn't going to sell much.

As for the comment that C can produce code as good as assembly, on some architectures its almost impossible to write assembly that's as good as the compiler because its very difficult to keep track of what combination of instructions will cause pipeline stall. It aslo makes it very difficult to follow the output

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf