What's the file extension for assembly code? Can it even be written by a text editor?

My plan was to use nano to write the program (for syntax highlighting), so would that work? If not, what do I need to use?

Can you even compile ARM assembly code?

  • 1
    Is there a universal standard? Do you think that might depend on the assembler you plan to use? The Gnu Compiler Collection (gcc) on the Pi seems to use .s if you choose to see the assembler produced by the compiler for a C source file.
    – joan
    May 10 '14 at 11:23
  • There are two main standards for ASM, AT&T syntax and Intel syntax, dominant in *nix and Windows worlds respectively. Nano should work okay, though you won't be able to tell it to explicitly syntax highlight ASM language, which you can do with, say, Gedit or Geany (would have to be installed.) As far as I can tell, gcc compiles ASM just fine. Granted, I have only used it on my Ubuntu system, but it should work pretty similarly on the Pi. May 12 '14 at 18:55

Assembly is a programming language, and, like other programming languages, you have plain text source codes that can be edited by all text editors out there.

The confusion comes from the fact that, as it is the lowest level programming language just above machine language, other programming language's compilers will generate assembly source-code from their language source codes. As a matter of fact, that's pretty much the definition of compilers: to produce assembly language code from their original language source codes. Wikipedia has a good article about compilers you should take a look to understand this process a little better.

Now once you have assembly source codes, you use an assembler to produce machine code. The assembly source code is specific to the computer architecture, in RPi's case, ARM.

GNU's gcc (the most common compiler you use for compiling C source codes in Linux) has also the assembler that will get an assembly source code and generate the executable machine code from it.

Coding in assembly is very hard and not something to be taken lightly. This comes from the fact that it is mapped 1-to-1 to machine code, so you need to know every nuts and bolts details of the architecture you are developing for. An assembly source code for the PC can be completely different from the same application code for the ARM, for example. They are not interchangeable. Second part: all the libraries out there you use to make your developer-life easier (not only the higher level ones, I am talking libc here) aren't readily available for assembly programming. You cannot call functions like printf() or scanf() that easily. It is doable, but not the same way you would do in C for example.

Coding in assembly is somehow limited to very small footprint applications and embedded devices nowadays. Only applications with very limited resources (like very small embedded systems) justify the hassle and effort needed to write assembly code. And not to consider the fact that it is also very hard to debug and maintain. I myself have written an assembly program one morning and the next day I would have no idea how to make simple changes on the source code. You need to document it A LOT.

Now answering your question:

If you write a source code in C (something simple, please!) and use the following gcc command, you will have the assembly code as the output:

gcc -Wall -S test.c

Check the test.s file.

Now if you want to generate the machine-language object from that assembly file, just go with:

gcc -c test.s

And then to generate the executable:

gcc test.o

Your executable will be in the a.out file.

If you remove the "-c" option from the "test.s" assembly command, it will generate the executable directly.

  • The problem with that is the compiler might not generate all the modes you can use in assembly language. There is thumb mode and neon mode. The neon instructions can speed up vector math for instance.
    – PaulF8080
    Dec 19 '16 at 17:44

Assembly program files have .s extension (.s because during pronunciation it makes starting sound of assembly, I think so)

  • open file with:

    sudo nano filename.s
  • save it with Ctrl+X then Y

  • assemble it with:

    as -o filename.o filename.s
  • link it with:

    gcc -o filename filename.o

It will create an executable file with name filename, execute it with:


If you are not interested in command line usage then install codeblocks, an IDE for such things by:

sudo apt-get install codeblocks
  • To be really picky, it's .S not .s
    – PaulF8080
    Dec 19 '16 at 19:31
  • @PaulF8080 No, it's not. .s is the common extension assembly source and .S is the common extension for assembly source with C preprocessor support. You assemble .s file with as while .S file need to use gcc or pass the file through cpp first. Sep 27 '20 at 14:47

There are two extensions commonly used for assembly sources: .s and .S. They are simple plain text files and can be edited with any text editor.

Pure assembly sources use the .s extension and are compiled using an assembler as. This is commonly called assembling instead of compiling.

The .S extension is used for assembly source files with C preprocessor directives. This allows the use of #include, #define, #ifdef, ... or C/C++ style comments just like in any C source. This allows for example including a common header in both assembly and C files to share defines.

The assembler though has no clue what to do with C preprocessor directives so .S files have to be preprocessed using cpp, the C preprocessor, first. To make things easier gcc automates this. So when you pass a .S file to gcc it will first call cpp and then as.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.