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

161

u/SmoothB1983 Oct 31 '15

In my degree assembly was mandatory for CS. It was a lot of fun and was a huge assist in understanding how my assembled code would work. You are right in that a lot of my colleagues never touched it and thus lack basic knowledge of how compiled code actually works.

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)

→ More replies (3)

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.

→ More replies (1)

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.

→ More replies (1)

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.

→ More replies (10)

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.

→ More replies (7)

2

u/[deleted] Oct 31 '15

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

→ More replies (2)
→ More replies (6)

13

u/[deleted] Oct 31 '15

We had a mandatory compiler course where we built an assembler to turn (a subset of)MIPS assembly code into binary, and (a subset of)C++ code into assembly.

I promptly forgot just about everything I learned about MIPS after, and haven't needed it much since, but the understanding of what is happening and how different languages are compiling or being interpreted was invaluable.

15

u/klug3 Oct 31 '15

MIPS is actually pretty sane when you compare it with say x86.

7

u/Abaddon314159 Oct 31 '15

x86 is actually pretty sane when you compare it with say sparc

5

u/klug3 Oct 31 '15

That's a bit surprising honestly.

2

u/[deleted] Oct 31 '15 edited Oct 31 '15

Pretty sure sparc is the microprocessor that is used in Voyager.

Edit: Nah, I'm an idiot... misread something somewhere else.

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

5

u/d4rch0n Oct 31 '15

In ARM the processor can be in ARM mode, Thumb mode or Thumb2 mode. In ARM mode it uses 4 byte instructions, in thumb it uses 2 byte instructions, and in thumb2 mode it uses a mix.

It can push multiple registers to the stack at once.

PUSH    {r1,r4-r7}  ; pushes r1, r4, r5, r6, and r7

I'm not sure how hard it is to write from scratch, but I know it is a bitch to disassemble. If you're trying to discover functions in the code, you literally need to look for jumps to memory addresses and see whether it jumped to an even or odd offset to figure out what mode the processor is in. Otherwise, you'll get junk instructions, disassembling from an offset in ARM or thumb.

In the end though, all this shit is basically the same. That's why you have intermediate representations. 99% of it's all push pop load store mov, etc. You know one and you're going to know most assembly languages.

but yeah, a newer intel processor has a shit ton of instructions. I'd way rather have to be an expert at writing MIPS than an expert at writing x86.

→ More replies (3)

19

u/jjmc123a Oct 31 '15

Which architecture? There is no such thing as "assembly" actually. I've done x86, Motorola 8600, macro (DECs assembly), Modcomp, SEL, and control data assembly and they are all quite different (CDC is very weird, you load a register with and address and another corresponding register automatically contains the value).

I've also done Fortran; really though, all NASA has to do is find some programmers and train them in the technology.

I'll say it again. The languages are not where the knowledge lies. It lies in the application structure and the library used by the environment.

2

u/SmoothB1983 Oct 31 '15

x86, MIPS, and SPARC. Once you've done a few it is easy to learn more. The general theory applies to different configurations and instruction sets. Once again the target architecture is not a big deal from a CS perspective, getting to the target is another story altogether.

2

u/Alborak Nov 01 '15

It's true, any good programmer can pick up a new language to a decent level pretty quickly. However, good luck getting young talented people to work for government programs, and good luck keeping them. The pay is far below commercial, and the tech skills don't transfer well. NASA is likely far better off finding the few expros who are willing to jump ship to work for them than taining people.

7

u/hellnukes Oct 31 '15

I just graduated information systems and computer engineering last year and I also had to learn assembly! It was one of my favorite projects by far. Had to create a game with a tank and some aliens with minimal ai (basically move to player). I learned so much about everything computer related during that project that I wouldn't otherwise.

We were given an in-house simulator written in java called PEPE in which you could basically simulate a CPU, memory, screen etc and wire it directly to the interrupts and CPU ports and etc, and you basically just loaded the assembly directly in the CPU and went to work. I thought every cs course had this too as it was basically my only serious low level project where you really got to see what happens down there.

→ More replies (8)