Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – RPi Awesomeness May 12 '14 at 18:55
up vote 10 down vote accepted

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.

share|improve this answer
Thank you, that was a perfect answer! – Beta Decay May 10 '14 at 16:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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