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?
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?
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.
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.
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:
./filename
If you are not interested in command line usage then install codeblocks, an IDE for such things by:
sudo apt-get install codeblocks