36

In the MIPS simulator "QTSpim", three types of files are accepted:

  • .a
  • .s
  • .asm

Is there a difference between those filetypes, and if yes, what is the difference?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Nicolas Brauch
  • 497
  • 1
  • 4
  • 10

1 Answers1

51

In Unix/Linux systems:

  • .a is the usual extension for static libraries (aka Archives of multiple .o files, made with ar(1)). Dynamic libraries, aka Shared Objects, use .so.
  • .s is used for asm compiler output. (gcc -S foo.c produces asm output, with a default filename of foo.s)
  • .S is used for hand-written asm source files. gcc -c foo.S runs it through the C preprocessor (so you can use #include<>, #if, #define, and C-style comments.) Some C headers, like asm/unistd.h only have #defines, and so can be included in a .S to get definitions like __NR_write system call numbers, for example.

In x86, there are two separate versions of asm syntax: AT&T (used by Unix compilers like gcc), and Intel/NASM (with a couple dialects, like MASM vs. NASM itself).

.S is appropriate for asm in GNU as syntax, whether you use any C preprocessor features or not.

In x86, .asm is more often associated with Intel-syntax NASM/YASM, or MASM, source code. Outside of x86, it's probably a good choice for asm source files that could be assembled by the platform-specific assembler, if it uses different directives than GNU as.

The glibc source tree uses .S for all asm source files.


People with a gcc background might put their MIPS asm into .S or .s files, while people with more NASM/YASM experience (or Windows), might go for .asm.

I'd recommend against .s files, because it's easy to accidentally overwrite with gcc -S foo.c.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    .s is backend generated assembler. IOW it is assembler written by a compiler. The traditional Unix extension for actual handwritten assembler is .S (capital). Since most compilers don't generate textual assembler by default .S is better comparable to .asm. – Marco van de Voort Dec 04 '15 at 23:27
  • 2
    In fact, .a is the name of a `ranlib` generated library/archive. From what I remember 25 years ago, it actually meant "archive." – David Hoelzer Dec 05 '15 at 02:51