Which is better NASM or GAS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ABHAYRAJ2021
Posts: 1
Joined: Wed Jul 22, 2020 12:35 am

Which is better NASM or GAS

Post by ABHAYRAJ2021 »

Hello friends

I am developing an OS and confused a lot which assembler and linker to use NASM or GAS.
I have read many BOOKs and many say use NASM and many says Use GAS so which one will be actually better for a large development program.

Please answer sincerely since I want to make a grand project and even highlight your reason why you prefer your choice

Thanks in advance.......
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Which is better NASM or GAS

Post by Octocontrabass »

I don't think it really matters which one you choose. The biggest difference between the two is the assembly syntax they support, but you can write the same code equally well in any syntax. The only other difference I'm aware of is NASM's built-in linker for flat binaries; GAS requires you to use an external linker even if your target is a flat binary.

Personally, I find NASM syntax much easier to read and write than AT&T or Intel syntax, so I would choose NASM.
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Which is better NASM or GAS

Post by Velko »

Long time ago I chose GAS. Still using it.

Main reasons:
  • You do not need to install another tool. AS is included with GCC (or was that Binutils?). Then there is no difference whether you compile .c or .S files.
  • It's the syntax you get when disassembling with objdump -d. You do not have to "switch brain modes" to understand what's going on.
  • It's what you get in GDB if there are no sources loaded or you want to instruction-step into C code.
As I said it was long time ago. Since then I've learned that tools have command line options to switch the syntax. But I'm sticking to defaults anyway.
If something looks overcomplicated, most likely it is.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Which is better NASM or GAS

Post by bzt »

Which is better NASM or GAS?
FASM. Period. :-D

If you're asking which one has the better language support, then I say that's a personal preference. (NASM uses Intel syntax, GAS can use both AT&T and Intel syntaces). But you should be able to convert between these dialects, if this is a problem, then maybe Assembly and OSDev is not the best hobby for you.

If you're asking which one has the better instruction coverage, then I say both are good enough. That is, for x86. NASM can't compile to ARM, GAS and FASM can.

If you're concerned about your build environment, then GAS is already included with GNU toolchain, NASM has to be installed separately.

If you are asking which is the fastest, most memory efficient, easiest to port, has the most advanced macro capabilities, then the answer is FASM, no doubt. (You can calculate checksums using only macros in FASM, something impossible with NASM and GAS. And this is just one example.)

Cheers,
bzt
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Which is better NASM or GAS

Post by Octacone »

NASM, its syntax is much easier/cleaner and it is easy to use.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Which is better NASM or GAS

Post by nullplan »

GAS, since it is included in the binutils which you need anyway.

There, now you've had opinions for all choices. I'm only waiting for a TASM proponent to show up.
Carpe diem!
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Which is better NASM or GAS

Post by iansjack »

And, for our Windows friends, there's MASM.

They all do the same job. I stick with GAS - why introduce more tools when you already have ones that do the job?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Which is better NASM or GAS

Post by nullplan »

Ooh, one more argument for GAS that might be more meaningful once you get to userspace: GAS has support for all specified ELF relocation types. NASM support for such is a bit spotty (for instance, as I recall, it is impossible to emit TLSIE relocations). Not that you need that in a kernel, since a kernel has no loader to set this all up, and usually no thread pointer, either.
Carpe diem!
User avatar
bellezzasolo
Member
Member
Posts: 110
Joined: Sun Feb 20, 2011 2:01 pm

Re: Which is better NASM or GAS

Post by bellezzasolo »

nullplan wrote:Ooh, one more argument for GAS that might be more meaningful once you get to userspace: GAS has support for all specified ELF relocation types. NASM support for such is a bit spotty (for instance, as I recall, it is impossible to emit TLSIE relocations). Not that you need that in a kernel, since a kernel has no loader to set this all up, and usually no thread pointer, either.
Unless you write one, that is. It wouldn't be too difficult to get a kernel to parse itself, even... I've done that before.

But my current kernel has a separate loader that includes a dynamic linker.
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
Post Reply