5 ms·
Why would anybody use this over the assembler shipped with their compiler? This might make sense if your project is written entirely in assembly, but does anyb
by miki123211 3y ago
Why would anybody use this over the assembler shipped with their compiler?
This might make sense if your project is written entirely in assembly, but does anybody even do that nowadays? For projects that are mostly in C/C++ with bits of assembly here and there, it's yet one more dependency your users have to install.
- x2rj 3y agoIf you write cross platform software, you might want MSVC on Windows and gcc on linux and their assemblers masm and gas have very different syntax. nasm outputs object files for both directly. Also the syntax in the context of especially macros is often a little better.
- DonaldPShimoda 3y agoPerhaps a small use case, but nasm is used in UMD's compilers course (https://www.cs.umd.edu/class/fall2023/cmsc430/ https://www.cs.umd.edu/class/fall2023/cmsc430/). And while that in itself is maybe not particularly exciting, I think the underlying point is more that assemblers like nasm allow for the implementation of toolchains like this, where you have some assembly with some C code. While not common, I'm sure cases like this are also not exceedingly rare.
- dfox 3y agoNASM has a logical and sane syntax that is both readable and maps directly to the generated instructions, in other words it is designed to be written by hand, not as an convenient intermediate format for the compiler to generate. Contrast that to typical AT&T-syntax x86 assembly with bunch of meaningless punctuation and complex addressing modes represented by bunch of comma separated numbers. And with MASM that needs bunch of boilerplate and noise words, because the syntax is motivated by what was required to produce real-mode 16b object files.
- jwr 3y agoTrust me, at least on Intel, you do not want to write assembly inside your C/C++ code, unless it's just a couple of lines. The usual AT&T syntax will drive you nuts, and the additional syntax for embedding assembly only adds to the misery. For any reasonable amounts (say, you want a function or several) of assembly, you want Intel syntax and standalone assembly files. NASM is a great tool, although YASM should also be mentioned: https://yasm.tortall.net https://yasm.tortall.net — YASM is what I used when I optimized an H.264 decoder for Intel-compatible CPUs way back in 2005 or so.
- kouteiheika 3y ago> The usual AT&T syntax will drive you nuts, and the additional syntax for embedding assembly only adds to the misery. It's trivial to enable Intel syntax in inline assembly even under GCC. And if you're using Rust instead of C or C++ then the inline assembly syntax is actually really great and very pleasant to use.
- benj111 3y agonasm has better goto labels you can use sublabels within a block that don't need to be globally unique. The data generation stuff is better aswell. This was a while ago, and I could have missed these features else where, but that's why I ended up at nasm. Yes, if youre just doing a bit of assembly, use whatever, but if you're doing a bigger project in assembly, nasm is optimised for that, rather than dealing with the output of a compiler.