r/programming • • Oct 31 '15

Fortran, assembly programmers ... NASA needs you – for Voyager

http://www.theregister.co.uk/2015/10/31/brush_up_on_your_fortran/
2.0k Upvotes

660 comments sorted by

View all comments

Show parent comment

105

u/klug3 Oct 31 '15

Well, most CS people do it as assignments or whatever for a course or two. Whereas in EE there are at least a few areas where assembly is used a lot as part of the job.

47

u/Cyph0n Oct 31 '15

Embedded systems is where it's used the most. When you're writing code for a 128K microcontroller, or a DSP, assembly is basically required. Yes, manufacturers provide C libraries, but you sometimes need to manipulate the hardware directly.

181

u/lilmul123 Oct 31 '15

Guy employed in the embedded systems field here.

Eh, that's not really true anymore. C compilers have become so efficient now that it's usually agreed that the C-compiled program is at least or sometimes even more efficient than a program that was written in assembly by hand. That's even without regards to the dozens/hundreds of hours saved not programming in assembly.

66

u/[deleted] Oct 31 '15

this.

filling a 128kb uC with assembler is insane.

use C. optimize with inline assembler if necessary.

12

u/vanderZwan Oct 31 '15

There are even compiles-to-C languages specifically designed with embedded systems as their intended use-case:

http://ceu-lang.org/

(ok, ok, I only know of one, but surely there are more)

2

u/AngryElPresidente Oct 31 '15

Nim is also one, they also have a compile to C++ option as well

→ More replies (2)

12

u/Reaper666 Nov 01 '15

this

But that's C++...

4

u/[deleted] Nov 01 '15

this.

no this is a pointer, you must use this->

→ More replies (2)

13

u/rubicus Oct 31 '15

For DSPs and similar they far from always use the full potential though, right? The optimal sollution should be writing in C, use a profiler to find the performance/power critical parts of the system and there use inline assembly. I'm still just a student but that's what I'm being tought at least.

3

u/ijustwantanfingname Nov 01 '15

Mostly correct, but I wouldn't even bother with the profiler. Check your timings with a scope, and optimize any segments which are outside of spec.

3

u/lilmul123 Oct 31 '15

If you need down to the microsecond precision (perhaps in some DSP applications), then assembly language, including inline, will be your best bet. For 99% of applications, though, C is a better option.

7

u/im-a-koala Oct 31 '15

Yep. I used to be an embedded developer and we had some small programs like that, but they were almost entirely written in C. The only time we used assembly was when we needed to do something that wasn't easily expressed in C.

2

u/Netzapper Oct 31 '15

The only time we used assembly was when we needed to do something that wasn't easily expressed in C.

Right, and even then it's still in the C source... the absolute minimum number of assembly instructions possible, wrapped in an __asm__, wrapped in a C function.

2

u/[deleted] Oct 31 '15

Another guy employed in embedded systems field confirms this.

If you want to write assembly code, you'd better have a good reason for it. Assembly code is often harder to debug, it requires a great deal of platform-specific knowledge to verify it... in short, if you can avoid writing it, you do.

3

u/[deleted] Oct 31 '15

Only used assembly for debugging. Compiler bugs suck hard. I don't really do embedded though. So many SoC are basically fully powered.

→ More replies (9)

21

u/hak8or Oct 31 '15

128k microcontroller? I am assuming that is 128kB of flash, in which case, this is really not true. Hell, 128KB of flash is actually pretty nice, I would even consider using c++ at that stage. I feel assembly only becomes worthwhile for the general program when you start hitting less than maybe 8 KB of flash and 512 bytes of ram, and you have a somewhat beefy amount of functionality to implement.

Maybe for very performance critical sections where you saw that the compiler does a poor job and you can do better, but otherwise, heck no.

Even with arm's cortex M series, interrupts no longer need to have any assembly based context switching. And even if it did, arm provided various c wrappers in their cmsis pack.

2

u/Cyph0n Oct 31 '15

Yeah, you're right. 128K is indeed plentiful in the embedded world! Writing assembly would be more useful in more constrained micros.

3

u/[deleted] Oct 31 '15

Honestly I am quite curious here. What kind of functionality can you implement on a system with 8KB flash mem and 512 bytes of ram? I have an Arduino but for the life of me can't figure out what to use it for..

4

u/zippy4457 Oct 31 '15

Quite a bit if you're hand coding assembly. The original Atari 2600 only had 4kb of rom and 128 bytes of RAM....so, missile command or asteroids.

2

u/msthe_student Oct 31 '15

Microwave ovens, Engine Management Units, ovens, dish washers, dryers, coffee makers, ...

→ More replies (2)

2

u/[deleted] Oct 31 '15

You could just roll your own Forth instead of doing everything in assembler. :)

→ More replies (2)

4

u/SmoothB1983 Oct 31 '15

Maybe most. The better state schools and ivies will have more than a course or two. The students that go on to become the top tier devs will typically have taken OS and Compilers (and even more advanced classes that build upon that knowledge).

Guess what is all over the place there? Not just assembly, but writing the program that makes assembly code. This is way different skill set than what EE does, and involves a deeper understanding of how it works at a more abstract level while still requiring that indepth knowledge that EE needs.

4

u/klug3 Oct 31 '15

Well, any CS degree without OS and Compilers is obviously shady, but those courses usually end up using a MIPS simulator or something like that, so yeah, you get the idea of assembly, but don't end up being an expert in writing assembly for say low level embedded code, still requires specific experience.

→ More replies (3)
→ More replies (1)