8 ms·
Assembly Language Programming: Still Relevant Today (2015)
- dang 7y agoA thread from 2015: https://news.ycombinator.com/item?id=10522158 https://news.ycombinator.com/item?id=10522158
- aportnoy 7y agoThis is like being an architect and noticing that bricks and cement are still relevant... Of course they are!
- rs23296008n1 7y agoSome architects are surprised by the requirement to have load bearing walls.
- neonate 7y agoIt's more like being an architect and working with bricks and cement yourself. The author's argument is that sometimes an "architect" should do that. Agree or disagree, but it's certainly not a truism.
- kazinator 7y agoAn architect might in fact design something down to the brick-and-mortar level, such that someone else assembles it to the actual building. That architect is working with bricks and cement, effectively at the design level. That's the same as using assembly language, rather than poking binary/hex values into memory.
- Lerc 7y agoThere's food for thought there. As part of my current project I wrote an assembler for 8-bit Avr. (on github https://github.com/Lerc/AvrAsm/ https://github.com/Lerc/AvrAsm/ ) Part of my motivation for this was to have an assembler that ran in the browser (for my fantasy console that also runs in the browser), but another big part of it was to write an assembler designed to be more friendly to people writing assembly directly. When I wrote 6502 asm I mostly did it from Supermon which is a no frills experience. It's nice to see the features that assemblers have now, I think I'll be implementing quite a few of those macros from this link in my own assembler.
- chrisseaton 7y ago> Assembly language yields maximum control and execution speed. It yields the only control and execution. Almost programs are generated through an assembler and assembly language. How could it possibly not be relevant?
- saagarjha 7y agoThere are a huge number of software engineers today, dare I say most, who cannot read or write assembly and are isolated from it by multiple layers of abstractions.
- chrisseaton 7y agoI know it's abstracted away, but it's still relevant to how the programs run because almost all programs go through an assembly language phase.
- saagarjha 7y agoWhat languages don’t? All of them execute on the processor in some way.
- chrisseaton 7y agoYou can generate machine language without an assembly language intermediate phase, if you just directly put bytes into a file. But most compilers have some kind of assembler in them.
- cryptoz 7y agoI could be mistaken, but, don't JVM languages avoid assembly steps? They use bytecode and are translated directly to machine code; I'm not sure there is an translate-to-assembly step. I'm also not sure how much of this confusion is semantics vs actually different components of the compilation and running process.
- 7y ago
- joe_the_user 7y ago"...self-modifying code, [is] sometimes appropriate to solve certain problems that have no other solution, or for improving efficiency, as in double-indirect addressing." I have read that self-modifying code on the x86 architecture is pretty dangerous at the assembly level. More broadly, this kind of comes back to all the issues in the "C is not a low level language" thread. Some level of assembler certainly gives the programmer as full access to the machine as possible. But naive assembler from the 8086 - 80486 eras is going to be rearranged in a lot of ways in a modern Pentium processor and counting on in-order execution may be a mistake. Edit: at the same time, the modern processor doesn't really allow a lower level than assembler normally and the default approach is assuming flat memory but being aware of the pitfalls of multiple caches being involved.
- saagarjha 7y ago> I have read that self-modifying code on the x86 architecture is pretty dangerous at the assembly level. Dangerous in what way?
- anfilt 7y agoHaving written self modifying x86 code. The most annoying thing is that instructions are not a fixed width. This means patching code requires you are able to parse every instruction, or a look up table where each instruction starts or just regenerate the entire code whole cloth. This also can cause problems if self modifying code has more than one thread since you suddenly may need to update 1 to 15 bytes atomically. Generally, easiest to do the last or put NOPs or doing something like windows hot patch point for functions. Where hot patchable functions are preceded with a 5 bytes of nops, and the function always starts with MOV EDI, EDI which again is a pretty much a NOP, but takes two bytes. This allows one to replace MOV EDI, EDI to a short jump to the start of those 5 bytes which is large enough to hold a long jump to any code. Windows went this route because originally multi byte NOPs where not part of the spec so if you used the one byte NOPs not only would each nop need to be execute slowing down function calls, but in multi-threaded code you would have to lock all threads to edit the code since it would be fetching on byte at time ect...
- 7y ago
- FpUser 7y agoAs recently as a year ago I used built in assembler in Delphi to perform some low level timing. It was not for just super-duper performance though. Surprisingly it was the most straightforward and simple way. Meanwhile my firmware for 3-Phase AC motor torque and speed control for really low power micro controller was doing fine with plain C without any assembly.
- 7thaccount 7y agoWhat do you do for a living?
- FpUser 7y agoI design and develop product for living. Universal guy. Mostly software but sometimes part of it is also firmware / elecronics / hardware. I happened to be a person who did everything from billing systems and other giant products for TELCOs and down to firmware for micro-controller. Some products I own and some are made to order. Some I did on my own and for some I was a leader of big team
- pjmlp 7y agoSure it is, someone has to write compiler backends and OS bootloaders, even if all instructions would be exposed as intrinsics.
- deleted 7y ago[deleted]
- shaggie76 7y agoWhile I can only recall writing real assembly once in 20 years I've read disassembly thousands of times while debugging.
- buserror 7y agoI'm rarely keen on posting negatives on articles that clearly took a lot of time to make, but I think this requires a bit of correction. I think this article is very, very simplistic. All of it relates to a 8 bits CPU that is 40+ years old. I switched to HLL as soon as I could get my hand on a compiler, namely, UCSD Pascal at the time! Then the Pascal, then to C and then myriads of other languages. I covered 6502, Z80, 68k (all of them, to 68040), PowerPC (all of them from 601 prototypes to G5s), ARMs (more than I can count) and x86s (same). True to be told, the assembly language I started with /helped a LOT/ with be becoming an efficient developer; a developer who understand what 'code' is being generated when he writes an expression, a statement, a loop, and one who understands what the runtime implication are for most of the 'sugar coating' HLL gives. However, starting (a bit) with the 68k, then even more so with the PowerPC, it became pretty much impossible to write /from scratch/ an assembly equivalent that was QUICKER than the compiler generated code. That was 20+ years ago. DRAM latency happened, pipelining happened and SIMD happened. Today, hand writing assembly is pretty much stupid on modern CPUs. Given the register files, timings, shadow registers, bus latencies etc etc the compiler will ALWAYS be better because there is so much criteria to think about when generating code... I'm not saying that having the knowledge is not useful; the best use of assembly is to write some code il HLL, one that is supposed to be super-mega-critical-quick, then disassemble it and see how it looks. More often then not, you can't make it better than it is in situ -- most of the time you will gain is to prepare your data better, align it better etc etc -- basically, 'hinting' the compiler to do a better job. You can do serious code butchery like that, without a hint of assembler [0]. But really, I haven't written any assembly for /performance reasons/ in 15 years, and that was Altivec on PowerPC. For 8 bits, it's all smooth as butter, but the article also doesn't take into account the massive progress in compilers; I'm the author of SimAVR [1] and I've seen my load of generated code for that CPU, and the GCC toolchain is /very hard to beat/ by hand these days. [0]: critical audio loop on one of my old PCI card driver, converting float<->int, applying gain etc while using the register file to the max, and making most use of the pipelining of the G4 (at the time) https://gist.github.com/buserror/0a3a69cca927b8da6c9c7ee1605007fc https://gist.github.com/buserror/0a3a69cca927b8da6c9c7ee1605... -- note, the inner loop was generated by a script that was doing the cycle calculations (!) [1]: https://github.com/buserror/simavr https://github.com/buserror/simavr
- 7y ago
- zzo38computer 7y agoThere is many kind of assembly language, some for the actual computer hardware, some for VMs, and some used as both. I have used and sometimes still do use assembly language, including 6502 (specifically, NMOS 6502 without decimal arithmetic, including unofficial opcodes), and a little bit of x86 stuff (although the modern x86 is very messy, I think), but also Z-machine and Glulx. I have also used MIX and MMIX assembly (and may use MMIX more if I would actually make a computer with it). And then some other programs (such as ZZ Zero, which is similar to ZZT) has its own kind of assembly language. One feature not mentioned is the relative numbered labels such as 1H and 2H available in MIXAL and MMIXAL; you can then use 2F to find the next 2H label forward, or 2B to find the next 2H label backward. My own assemblers for Glulx and ZZ Zero support the similar feature too.
- commandlinefan 7y agoHe does touch on local labels briefly - he suggests (and I agree) that you can get the same effect, more maintainably, with macros.
- zzo38computer 7y agoMacros are good too, although I think both are useful.
- mjpuser 7y agoNot sure why HN is saying it is obvious that assembly is relevant because compilers... The article's intent is around a programmer writing assembly. I'm sure there are niches but I can see web developers getting away without writing assembly in their professional career.
- jkoudys 7y agoMight see that flip in the coming years, if you consider web assembly (wasm) to be assembly. I do.
- pizlonator 7y agoWebAssembly is not assembly in the ways that the article talks about. Like, writing it directly doesn’t give you any special control or guarantees over timing.
- jkoudys 7y agoIt's assembly against a virtual machine, not a physical one. You're right it's not appropriate for an embedded system or some other RTS, but assembly doesn't stop being assembly when you target a virtual machine.
- pizlonator 7y agoIt kinda does in this case. Don’t kid yourself. In real assembly, the really interesting part is how to use a finite register file. WebAssembly has an infinite slab of variables available, in the sense that you get to say how big it is. That fundamentally changes the game.
- pjmlp 7y agoThere are real CPUs that are just like that. In fact, most mainframes have always made use of microcoded CPUs, with Assembly being referred as bytecode on the programming manuals. You just need to dive into IBM and Xerox PARC manuals, for starters.
- peter_d_sherman 7y agoExcerpt: "Jeff Laughton (Dr Jefyll on the 6502.org forum) says, "I recall hanging out with a programmer pal o' mine and a younger fella who was in college. The young fella was complaining, 'We have to take assembly language,' and Len corrected him immediately, saying, 'You get to take assembly language!'" <g>
- dimator 7y agoWhat a great way to put it. What's great is that learning assembly is like taking the first step to understanding the bridge between software and hardware. I remember a taking class that started out as confusing as hell. The first few exercises seemed really mystical and just so brittle. You'd have to be a wizard to ever get this, one thinks. But by the end of the class, we made an asteroids-like game, complete with RNG based on input timing (the time between game execution and when the user clicked start). That was really an enlightening moment.
- davidhbolton 7y agoEven back in the 1980s, author Lance Leventhal who wrote some great programming books on assembly always warned that productivity wise you write the same number of lines of code whether its 6502 or C. As that 6502 example in the article shows, you don't great great productivity with assembly. And even macros don't improve on it that much.
- cmrdporcupine 7y agoOne writes 6502 assembly by hand because there is really no alternative on that ISA. It does not make a good target for a C compiler, there are very few of them to begin with, and hand written 6502 (or 65816) is going to be better than anything produced by any compiler for it at this point in time.
- georgeplusplus 7y agoTo me, assembly is one of the things while self studying CS that I felt lacked good support in resources such as this, MOOCs, or just plain explaining it. Usually when I post a topic trying to Demystify the topic I am greeted with an extremely hard to digest read about said topic that is more meant for people Already knowledgeable in the subject. And I feel assembly should be more a core building skill in a programmers toolbox. So this article is very welcoming for o me.
- faitswulff 7y agoI got a fairly good introduction to assembly with LC-3 (Little Computer 3, an instruction set for learning) programming in an elementary electrical engineering class in college. I haven't looked myself, but for those self studying, searching "LC-3" might be a good option for self-learning assembly.
- kick 7y agoModern assembly is kind of...bad. I would recommend checking out an old book for an old mainframe's assembly language. They're usually much less mystic by virtue of being much less complex. IBM had some really nice manuals and books; no one ever got fired for buying IBM because an IBM machine could be programmed by a dog. Octal is where it's really at, though, if you get really into this. A fun weekend project is to write an octal "decompiler" (ideally you won't have compiled anything, just having written some octal by hand) that allows you to reason with what it's doing by translating it to an actual language rather than just thin syntactic sugar over 1s and 0s. Octal itself isn't so difficult, it makes binary much easier to reason with, but this definitely helps you get a more intuitive sense of what is what. Of course, it's not something that has a substantial amount of value with modern machines. Maybe eventually we'll get back there; I think I'll enjoy it when we do. Until then, though, it's fun to play with.
- bear8642 7y ago> Octal is where it's really at Why octal, not hex?
- p0nce 7y agoOn modern x86 it's not very useful at all anymore. An ICC or LLVM backend with compiler intrinsics will get you quicker performance, with reduced maintenance and cost. Performance will also move over time with backend optimizations getting better. You can still do it if you care about debug build performance.
- commandlinefan 7y ago> It is common for the beginner to want all the fancy tools too soon Am I the only one who’s never felt that way? I get grief from people around me (especially “hurry up and get it done” management types) for spending too much time in the low levels, trying to really understand what I’m doing and what’s going on.
- FartyMcFarter 7y agoYou should change what people are around you, if possible.
- z3t4 7y agoOptimizations have come a long way. Not only do you need to be an asm programmer to beat the optimizer, you need to be a good asm programmer.