6 ms·
NASM Tutorial (2018)
- jdsully 8y agoAssembly is still quite useful in a number of circumstances. The compiler was generating terrible code for a ticket (spin) lock, and rewriting in assembly helped considerably [1]. Its also still the best way to get the most out of AVX and SSE. I find the register allocation to be extremely poor when using intrinsics. 1. https://github.com/JohnSully/KeyDB/blob/unstable/src/fastlock_x64.asm https://github.com/JohnSully/KeyDB/blob/unstable/src/fastloc...
- gpapilion 8y agoi agree with this, but find the complexity of writing assembly with modern processors instruction sets requires quite specialized knowledge.
- pjmlp 8y agoIt is, but someone needs to write compiler backends.
- elcomet 8y agoIt is quite scary to think that less and less people know how to write good assembly. So in a few years (decades?) we will have to rely on backends, with almost no one knowing how they really work, or how to write another one.
- reitanqild 8y agoLuckily it seems working on language design and compiler stuff is stuff is considered cool, almost as cool as game programming so I'm not too worried yet.
- pjmlp 8y agoI am not so negative, thankfully any good CS degree has enough compiler design lectures and assignments. And using sites like Godbolt is becoming trendy.
- stevekemp 8y agoI had fun recently generating Intel assembly for mathematical expressions: https://github.com/skx/math-compiler/ https://github.com/skx/math-compiler/ Mostly the project was to write something that compiled, from start to finish, but it was a nice refresher on assembly which I've otherwise not touched seriously for 20+ years.
- htfy96 8y agoThat's true, but not difficult as many people may think. In most cases you only need to remember most-used ~20 instructions and leave the remaining to reference. Sure it requires other domain knowledge, but it has almost nothing to do with asm itself.
- saagarjha 8y agoQuick question, I was skimming the code and came across this: xor eax, eax mov ax, 1 Was there a reason you didn't use the shorter xor eax, eax inc eax ?
- jdsully 8y agoI experimented with just mov eax, 1 and found it be slower - though I didn't try inc eax. Using 16-bit registers is tricky because they leave the upper bits unchanged. Its easy to trigger a partial register hazard inadvertently. p.s. the comments were nicely lined up in my editor, don't know what happened once it got to github.
- skissane 8y ago> p.s. the comments were nicely lined up in my editor, don't know what happened once it got to github. probably spaces-vs-tabs. GitHub has a different number of spaces-per-a-tab than your text editor. If one configures one's editor to expand tabs to spaces this won't happen.
- saagarjha 8y ago> If one configures one's editor to expand tabs to spaces this won't happen. …or you could use tabs for indentation, spaces for alignment, as they are intended to be used ;)
- skissane 8y ago> …or you could use tabs for indentation, spaces for alignment, as they are intended to be used ;) Yes. But, that is easier to stuff up. Getting rid of tabs completely, it disappoints some people who want to change the indentation amount to fit their personal preferences, but it reduces the likelihood of messes being made.
- saagarjha 8y ago> it disappoints some people who want to change the indentation amount to fit their personal preferences That's one issue I have with spaces, along with the fact that they are more annoying to delete. And I've seen people indent by 4n+1 spaces by accident at times (usually when there are no surrounding lines to provide context), so I wouldn't be so sure about it being the end-all, be-all for fixing indentation mistakes.
- interfixus 8y agoHello Nineties. Are you home? I miss you. I don't believe I've really thought or heard of Nasm for the last two decades, but boy is it time for me to dig it out again and get assembling. For absolutely nothing but the sheer fun of it and for reconnecting with my hardware. Thanks for posting.
- 4thaccount 8y agoDoes anyone know the best way to run assembly code on Windows? As usual, I seem to recall this is one of the many things that is easy in Linux and almost impossible on Windows.
- TACIXAT 8y agoThere are a lot of assemblers, but I've used MASM. It ships with visual studio. I think you can find the actual binary by searching for ml.exe or ml64.exe. Then you just write some MASM code and assemble it. It's less well documented but entirely possible.
- 4thaccount 8y agoThank you! I'll check!
- animal531 8y agoWell, since we're talking about NASM, go to https://www.nasm.us/ https://www.nasm.us/ and download the latest stable build for Windows.
- 4thaccount 8y agoDoes that use MINGW though and require you to build all that junk on Windows?
- jcelerier 8y agonasm is a single .exe
- pjmlp 8y agoIt is quite easy, specially since home computer Assemblers were historically more powerful than UNIX ones, with very expressive macros. Here is the relevant information for MASM. https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=vs-2017 https://docs.microsoft.com/en-us/cpp/assembler/masm/microsof... And some game development references of yore http://win32assembly.programminghorizon.com/tutorials.html http://win32assembly.programminghorizon.com/tutorials.html
- vgoh1 8y agoWow, NASM is really a blast from the past for me. 80386 assembly was my second "language" that I learned, after various forms of BASIC (on TRS-80 and QuickBASIC). In the mid-90's I was a teenager, and would write most of my code in QuickBASIC, and make optimized code in NASM. QuickBASIC was a compiled BASIC, but still pretty slow on a 386, so about half of my code base ended up being assembly. At one point, I made my own pseudo-language, which was actually just a few dozen commands that would be translated into NASM, to make programming in assembly much easier to deal with. I ran out of room on my 40mb hard drive, and also ran out of backup floppies that worked (I would 3x backup my important stuff, because the mid-90's was a terrible time for reliable magnetic media on a budget), so I would periodically delete source code that I had spent weeks programming. The interpreter was one of those casualties, which, thinking back, was a really dumb move (I was 15 or so, cut me some slack!), because I still kept a lot of programs that needed that interpreter to compile. I have those codebases to this day, and can run the executable on my retro DOS machines, view the code, but no compilation :-( I can't remember what my old assembler was, but I do remember NASM was a dream compared to whatever other assembler I was running at the time. I'm happy to see that it is still kicking. In case anyone is wondering why I would be running a 386 in the mid 90's with a 40mb hdd (and 1mb RAM!), it's just because my parents had the time had no money, and to them a computer was a computer - they couldn't see the advantage of 1mb vs 16mb of RAM, people in general were much less computer savvy. It wasn't until my 30's that my mother realized that my time programming computers as a teenager was actually something productive!
- pjmlp 8y agoOn my CS degree compiler assignment, I got to learn a neat trick from our teacher that I still use when advising someone trying to write a compiler. Basically, our IL was just a bunch of NASM macros. So yeah not good at all for doing register assignments or writing any kind of performant code, but it was a binary generated by our toolchain anyway, and it felt good.