Good day, dear gurus! There was a need to learn to assembler, and I don’t want to work on Windows on old stuff in the university, so they choose a laptop with Ubuntu 11.04 installed. Please tell me which packages I need to install to write programs on an assembler, and also how to build and compile this program from the console? In the future, it is planned to link the assembler with C ++, what is needed for this and what literature should be read?
3 answers
You need binutils. They have either as86 / ld86, or gas (GNU Assembler). A special feature of gas assembler is the use of AT & T syntax. Those. This means the following:
- the direct order of the operands (ie,
src, dst, and not vice versa, as on the Wintel platform); - All assembly instructions have a suffix that determines the size of the operands. for example, movb. No terrible constructions like dword ptr as in TASM / MASM :-)
- a different (than MASM / TASM) addressing format
- and much more
On the other hand, this syntax is close to the assembler syntax on normal, "big" machines.
In gcc, by the way, the AT & T syntax is used for assembly language, so I highly recommend it.
The most popular Linux assembler is nasm. Put apt-get install nasm. There are few books on assembler in Linux. A good book in English is Sivarama P. Dandamudi. Guide to Assembly Language Programming in Linux. Search the Internet. It describes how to work with us, how to compile, the structure of the program, the syntax, as well as general theoretical concepts of working with memory, processor registers, etc.
Here is another book in Russian Stolyarov A.V. Assembly language in Unix OS. She is on the Internet on the author's website in the public domain. Googled.
- And what debugger can you advise? - Yegor Sokolov
- onegdb - skegg
As an option, it is possible to use the built-in GCC assembler. Example
int main() { char *message = "Hello, world!\n"; __asm__("\ movl $4, %%eax\n\ movl $0, %%ebx\n\ push %0\n\ pop %%ecx\n\ movl $13,%%edx\n\ int $0x80" : :"g"(message) ); return 0; } And the result
gcc message.c && ./a.out
Hello, world!
- oneYes, but still it is better to first master the "independent" assembler, and only then move on to the built-in one. - skegg
- The option is very good, I will definitely study it, but first the basics - Egor Sokolov
- 2A very useful auxiliary tool for learning assembler is gcc (yes, the C compiler) with the -S key displays the assembler code of the C program. - avp
- gcc -S generates assembler code in the style of GAS, i.e. with the syntax of AT & T - skegg