135 points · by AlexeyBrin · 7y ago · 31 comments
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/fastloc...
xor eax, eax
mov ax, 1
Was there a reason you didn't use the shorter xor eax, eax
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.
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.
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.
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.
As usual, I seem to recall this is one of the many things that is easy in Linux and almost impossible on Windows.
Here is the relevant information for MASM.
https://docs.microsoft.com/en-us/cpp/assembler/masm/microsof...
And some game development references of yore
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!
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.