F
F
Follenlast2016-01-27 16:56:14
assembler
Follenlast, 2016-01-27 16:56:14

How to understand all these assembler syntaxes?

Hello dear toasters. I decided to start learning assembler. While looking for books and resources, I caught myself thinking that I don’t even understand the difference between all these assemblers.
GAS, MASM, TASM and the rest. Micro PIC has its own asm, AVR has its own. I just don’t know where to start. GAS uses AT & T syntax, other intel syntax. How, for example, do reverse engineers disassemble programs? He said that even each OS has a specific syntax. Please clarify a little. Now, if, for example, I want to write for x86 processors, then Windows will have its own asm, and its own for linux? Or how?
I know how easier it is to set it. Now, if hackers (no, I don’t plan to get even close to them, that’s not the point) writes a virus for hypothetically two absolutely identical computers. They have the same processors, everything is the same, only Linux is on one, Windows on the other , it turns out that assemblers will be different, and the same virus will be for these two computers on different syntaxes?
I apologize in advance for a very idiotic question.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
abcd0x00, 2016-01-28
@follenlast

I also got confused, then went the other way. I took the most popular assembler books and installed everything that was needed to study them. It is important not to put the freshest, but to be able to practice.
It turned out: Abel + DosBox + several translators.

[[email protected] PROGRAMS]$ ls
ASM86  HIEW_650  MASM61  TASM  TECH60
[[email protected] PROGRAMS]$

Now I work in MASM61 and TASM.
But TECH60 is like a guide to operating system functions.

M
Mikhail Kulikov, 2016-01-27
@shukan

It's better to write a program in C/C++, and then using the "-S" option, you can turn the output into assembly code and study it. The second option is to drive the resulting program into the debugger and study the code there. And most likely you will never need to write in pure assembler right away. It used to be popular, in the days of "640K memory is enough for everything."

A
Alexander Polyakov, 2016-01-27
@MakedonskyLF

Firstly, assembler is, in general, a digestible record of processor instructions (which is more or less convenient for a person to read). Accordingly, there are different processors (architectures), as a result, different commands, sometimes even the syntax may change somewhat. GAS, MASM, TASM - in fact, these are different assembler compilers and differ in the format of constructing a sentence (how the same thought is written differently in different languages ​​(very distant analogy)).
In modern operating systems, no one will let the program be executed directly (do whatever it wants). The OS imposes restrictions on what commands the program can use ... Plus, the format of executable files (headers) is different for Windows and Linux. Accordingly, the same executable file will not start on both systems. niche
Theoretically, it may even turn out to dodge and write such code in assembler that it will be compiled into an executable file for both systems, but the assembler will need to give different parameters (target architecture / OS).
Almost the only niche of assembler is low-level optimizations. When you drive camels through the eye of a needle.

V
Vasily, 2016-01-27
@Foolleren

assembler is almost like a processor language - and there are a lot of syntaxes, that's why they came up with C
to deal with assembler, you also need to read datasheets for processors along with books - there are all the subtleties,
if we consider assembler from the point of view of a high programming language, then we have
constants
registers (variables)
ports
flags
commands (functions)
memory (another type of variable can be said to be an array) a
stack
can forget something)
commands, in turn, can depend on flags or affect them, that's all, that's all assembler, the difference is that in assembly language, the program structure and types must be kept in mind, unlike a high-level language.
For Windows and Linux, the difference is that you need to call different OS functions in the header of the executable file, there is no difference in the assembler itself (unless, of course, Linux is spinning on any arma)

N
none7, 2016-01-27
@none7

The essence of any assembler is the transformation of command mnemonics into machine operation codes (opcodes), and the calculation of relative offsets by named labels. The opcodes themselves are the same within the processor architecture. You can even assemble a program for Windows, and run in Linux Wine directly access the Linux kernel system calls. Different assemblers (programs) have different code design, where are code segments, where are data and many other little-known options fed to the linker and OS. MASM and TASM differ only in this, but you can write compatible code, FASM command mnemonics differ slightly, but in general they all use Intel syntax. That is, the command mnemonics look absolutely identical. With GAS using the AT&T syntax, it's somewhat more complicated, the mnemonics are essentially the same, but each instruction is given the size of the operands and the order of the operands is reversed. Example of register expansion 1 byte to 4 bytes (move xxxb x=Zero):

movzx ecx, al (Intel);
movzxbl %al, %ecx (AT&T movzxb(yte)l(ong))

Both mnemonics will give the same opcode. There are assemblers using AT&T syntax not only for x86 and amd64, but the mnemonics themselves, as well as opcodes, are naturally different.
The disassembler, as the name implies, turns opcodes into mnemonics, sometimes analyzing the code globally, splitting it into procedures, finding their calls, or even matching them to structures and arrays. The syntax here is at the choice of the disassembler developer.

M
MiiNiPaa, 2016-01-27
@MiiNiPaa

Take the assembler you need and learn it. You need another one (say, for another platform or for integration with another build system) - learn it. Fortunately, assemblers for one platform usually differ in trifles.
The essence of assembler is direct commands to the processor. How many different instructions the processor has, so many different instructions in a particular assembler will be.
If there is an assembler for different operating systems, you can write the same code for these operating systems. But you need to take into account that as soon as you need to turn to the API of this OS, you will have to work hard here: which library to load, how to pass arguments, etc.

M
Montgomery, 2017-04-06
@Montgomery

I'm dealing with all this right now as well. Everything is so strange and incomprehensible. But here I dug out an excellent book by Stolyarov "Programming in NASM assembly language for Unix OS". Everything is very simple and accessible. I advise. Well, in general, there are a lot of resources with answers to such questions. Here is a good selection of books: https://proglib.io/p/assembler-books/ . There are Stolyarov, and Kalashnikov, and others like them. All 2011 and 2014. I can't find anything newer. Unfortunately, our Assembler is not as popular as we would like :( The thing is really necessary and interesting. Good luck in this field!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question