Prerequisites for Learning Assembly Language

I decided to learn assembly language because I learned that it has many advantages, we can directly interact with equipment, we can learn how computers are better, and much more. When I started to study it first, I found out that it was a little strange, and not like other programming languages, so I thought that maybe it will be difficult for me to learn. So, I'm just asking what are the basic prerequisites for learning assembly language. For information, I have already studied programming languages ​​such as C, C ++, C #, PHP.

+6
source share
5 answers

You must tell us which car you want to learn. ARM , x86(_64) , Sparc , etc. all different ISA.

If you just want to get acquainted with the world of assembler programming in general, the Randal Hyde Art of Assembly is good (although what you are writing is not quite an assembly, but rather a mixture between high and low level languages, it will introduce you to the concept well).

If you indicated your points of interest on x86 , I can recommend this book: Professional Assembly Language . Aside from this book, sandpile.org is a great resource.

For x86 choice of environment also matters. Here 's a great window programming tutorial at the University of Illinois Urbana Champaign. Studio ACM - SIGWINDOWS. For Unix, a great tutorial I met is this one . An excellent, more general resource is Dennis Yurichev's Reverse Engineering for Beginners . This book focuses on both windows and UNIX environments, and although it is reverse engineering, it can help you learn a lot about the fraud of programs running on your computer.

For ARM this article is an excellent introduction. This article is another great introduction.

+7
source

I started programming in the assembly about two months ago, and so far everything has gone very well. Let me give you a short summary of what I have learned so far.

Syntax

There are two main syntax for building x86: Intel and AT & T. For each, there are pros and cons. Intel syntax seems to be used only for x86-based processors, while AT & T syntax is used for several different architectures (e.g. ARM). If you look at the source code of OpenBLAS , you will see that they use AT & T syntax for several different architectures. However, many people think that Intel syntax is more readable. So far, I have programmed using Intel syntax, but I know how to read AT & T syntax for the most part.

Installers

You can use the built-in assembly with GCC, but not with 64-bit MSVC. So far, I have not worried about the built-in assembly. You can select several assemblers, for example: MASM , NASM , YASM , FASM and GAS . MASM uses only Intel syntax and is used only for Windows, as far as I understand (I do not think that it can be ELF object files for Linux). NASM also uses only Intel syntax, but can create several different object files, for example. for Windows and Linux. YASM, as far as I can tell, is NASM for the most part, but also supports AT & T syntax. FASM uses Intel syntax and can create several different object files, but it is slightly different from NASM and YASM. I haven't used FASM yet, but it looks alluring. GAS uses AT & T syntax (although Intel syntax can be used) and is actually used when compiling with GCC. GCC produces the assembly, which is sent to GAZ.

It is important to understand that each assembler has only a dialect, so you cannot expect that the code written in MASM is necessarily assembled out of the box in NASM. NASM and YASM are mostly compatible, as I understand it.

Which assembler should you choose? I have used NASM so far.

Conventions and C references

The best source of training for me so far has been GCC. Write the code in C, and then look at the assembly. For example, if you have a simple function foo , you can do

 gcc -O3 -S foo.c //AT&T syntax gcc -O3 -S -masm=intel foo.c //Intel syntax 

then look at the file foo.s or you can use objdump

 gcc -O3 -c foo.c objdump -d foo.o //AT&T syntax objdump -d -Mintel foo.o //Intel syntax 

You must know the function that invokes your OS conventions . The calling conventions are different for 32-bit code and 64-bit code. For Windows and Linux, they are the same for 32-bit code, but different for 64-bit code. So far, I just wrote build code with NASM for Linux 64-bit.

Many assembly issues in SO seem to be related to writing entire functions in the assembly, including data input and output. I do not think this is necessary. Let C take care of input and output. You can see an example of this question . I gave NASM code and C code, and also explained how to compile, compile and link them. This was one of the first things I wrote in the x86 assembly. In this question I had a function

 float triad(float *x, float *y, float *z, const int n); 

Linux x86-64 calling conventions (or rather System V AMD64 ABI) pass the first parameter in the rdi register, the second in rsi , and the third in rdx . So, in this case rdi=x, rsi=y, rdx=n .

Once you get the calling conventions and can link your object files to the assembly with C, you will find working with the assembly much easier.

Finally, the second best learning source for me was the Agner Fog Optimizing Assembly manual . There are many good tips in the first part of the beginner's guide. And as soon as you get some experience, there is a lot of good information in the later part of the manual.

+3
source

computer, assembler, a book describing the assembler language in question. since you know C, some C compilers even allow you to write assembly between C.

+1
source

You really don't need any prerequisites if you choose the right book.

I learned assembly language (the basics, I just don’t need anymore) as my first programming language (without any teacher) with the assembly language Step by Step: Programming in Linux 3rd Edition . He teaches the basics, but after reading this book you can easily read any other leading collections.

+1
source

The assembly is different from any of those higher-level languages ​​that you have already learned.

A good place to start is the x86 Registers, here is the site I found explaining to them:

http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html

Good luck

EDIT:

It is also always useful to start and stick to a specific assembly language, for example, I started with NASM , which is pretty decent and has some interesting features, such as character management and namespaces.

0
source

Source: https://habr.com/ru/post/977484/


All Articles