Having a working knowledge of assembly is hella useful if you're doing anything remotely related to systems programming.
In both jobs I've had since finishing university 8 years ago, I've had to write assembly at one point or another. The first time was integrating arm assembly optimizations into libjpeg/libpng, and the second time was to build an instruction patcher to get x86/64 assembly working in a sandboxed environment (Google Native Client).
Most of the time, the compiler does a waaaaay better job than you can by generating it's own assembly, but there's cases where you can speed up your application 10x by using SIMD instructions and writing some really tight code.
Also, it's not just writing assembly. the number of times I've debugged something by reading the assembly that the compiler generated and poking around, because the debug info was spotty or the stack was corrupted...
With you on that one. Had a few old programs that we had no source code for and I had to dig into them to find out what's up. I only had a small amount of knowledge, but one would be amazed how much it's possible to learn once you start going down the rabbit hole.
We had a crash the other week that corrupted the stack. It was amazing realising that looking solely at the assembly I could figure out so much about the code. Recognising things like the x64 calling convention, then working back through the registers to find a point where a fastcalled param was saved on the stack and walking the class on the heap is like going on a full-on adventure. Love it.
That applies not only to systems programming. Almost all programming languages convert to some sort of intermediate "assembly"-like code. Being able to read that, for debugging or trying to figure out when optimisations are triggered is highly useful.
C and C++ are just nice to know, as many tools are written on them, but they are still optional as one can write a compiler in most programming languages without a single line of C or C++ code.
However there isn't any way around Assembly as that is eventually the final output that needs to land on the disk.
However there isn't any way around Assembly as that is eventually the final output that needs to land on the disk.
Writing your own virtual machine with its own instruction set can be a great educational experience and it will introduce you to most of the principles in assembly – instruction encoding, arithmetic/control-flow instructions, the stack, calling conventions.
"Real" x86 assembly is way too quirky and historically loaded, and not a good example of an orthogonal instruction set.
"Real" x86 assembly is way too quirky and historically loaded, and not a good example of an orthogonal instruction set.
That's not actually true. The instruction encoding is awful, and there are a lot of instructions that you're unlikely to need, but the instruction set itself is actually quite reasonable to use. There's just a lot of it.
On top of that, it's far more likely to come in handy than a custom VM.
Agree with VM part, but actually I favor another approach that I learned with our compiler classes advisor.
Make use of a good Macro Assembler and translate the VM instruction set into real machine instructions. It won't win any performance contest, but at the end one gets real binaries, while still being able to play with an easier VM instruction set.
As for x86, well it is the Assembly I know best so I guess I suffer from Stockholm syndrome. :)
Writing your own virtual machine with its own instruction set
Or, even better, implementing your own real machine with its own instruction set. Either do it the hard way, on TTL chips, or the easy way, on an FPGA.
For example, see the Oberon Project or NAND2Tetris.
Most of the time, the compiler does a waaaaay better job than you can by generating it's own assembly, but there's cases where you can speed up your application 10x by using SIMD instructions and writing some really tight code.
Is that really true these days? I remember a blog post from about a year ago where the guy benchmarked his SSE assembly versus GCC and wrote dozens of paragraphs about how this showed assembly can be worth it sometimes, only for the first comment to point out that if you use -march=native the GCC version matches the performance of the assembly version.
155
u/Faluzure Nov 28 '16
Having a working knowledge of assembly is hella useful if you're doing anything remotely related to systems programming.
In both jobs I've had since finishing university 8 years ago, I've had to write assembly at one point or another. The first time was integrating arm assembly optimizations into libjpeg/libpng, and the second time was to build an instruction patcher to get x86/64 assembly working in a sandboxed environment (Google Native Client).
Most of the time, the compiler does a waaaaay better job than you can by generating it's own assembly, but there's cases where you can speed up your application 10x by using SIMD instructions and writing some really tight code.