# Assembler for beginners

In any business, the main thing is to start. Or here’s another good saying: “The beginning is half the battle.” But sometimes you don’t even know how to approach a question of interest. Due to the fact that my memories are still fresh, I hasten to share my thoughts with those who are interested.

I will say right away that I personally assemble not under the PC, but under the microcontrollers. But this does not really matter, because (unlike the AVR microcontrollers) the command system for these microcontrollers with a PC is extremely similar. And, in fact, he is an assembler and an assembler in Africa.

Of course, I do not set as my goal to describe in this article everything that is necessary from beginning to end. Fortunately, an incredible amount of literature has already been written in assembler. And yes, my experience may differ from the experience of other programmers, but I think it is not superfluous to outline the basic concept of this issue in my understanding.

To begin with, I will reassure inquisitive recruits: assembler is not at all complicated, contrary to the stereotypical opinion. It’s just closer to the “earth”, that is, to architecture. In fact, it is very simple, if you grasp the main idea. Unlike high-level languages ​​and a variety of specialized programming platforms (by all of the above, I mean anything like C ++, MatLAB and other similar things that require programming skills), the teams got around it once or twice. In the beginning, even when I needed to calculate the double integral, this task caused only bewilderment: how can such a procedure be performed with such a meager number of operations? Indeed, figuratively speaking, in assembler you can only add, subtract, and shift numbers. But with the help of assembler, you can perform arbitrarily complex operations, and the code will come out extremely light.
bset P2.0
And as they say, no problem. Need to turn on immediately four pieces connected in series? Yes, easily:
mov P2, # 000fh
Yes, here I mean that the novice fighter is already familiar even with number systems. Well, at least with a decimal. ;)

So, to achieve success in the matter of assembly, you should understand the architecture (in my case) of the microcontroller. This time.

By the way, one of the sore spots in the knowledge of architecture is the organization of memory. Here on Habré I saw the corresponding article: habrahabr.ru/blogs/programming/128991 . I can also mention key pain points: interruptions. The thing is not complicated, but at first (for some reason) difficult to perceive.

If you have a difficult task and you don’t even know how to approach it at first, it’s best to write an algorithm. It truly saves. And in the beginning, even if the program is completely not complicated, it is better to start with the algorithm, because this process helps to put everything in the head in place. Returning to the example with the calculation of the double integral according to experimental data, I thought about the algorithm all day, but then I wrote the program on it in just 20 minutes. Plus, the algorithm will be useful for further modernization and / or operation of the program, otherwise the assembler code, at times, if it will be understood line by line, then it will take a lot of work to figure out what the general idea is.

So, the second key to success is a well-written and well-designed algorithm. I strongly recommend not to sit down immediately at the device and write a program. You will not write anything sensible on the move. These are two.

Actually, I would like to write as Fandorin: “This is a t-t-three” ... But, I am afraid, we can stop here for now. Although I would like to add a few more recommendations and gingerbread.

To summarize my somewhat chaotic monologue, the key points in assembly language programming are knowledge of architecture and the coherent construction of thoughts. Of course, it is not necessary to immediately rush headlong into a study of literature describing the insides of the same PC, but a general idea (I repeat, at least for a start) will be very necessary.

And now the promised gingerbread cookies! Here I am crucifying about some incomprehensible assembler, but what, in fact, is good in it? Yes, a lot of things! Firstly, of course, you do not need to memorize many commands, libraries used, and other related rubbish. Just a couple of teams and, consider, you are fully equipped. Secondly, due to the extreme proximity to machine codes, you can do almost anything your heart desires (unlike the same high-level languages)! Thirdly, the assembler code, due to the maximum conciseness in the wording, is executed extremely quickly.

In general, solid pluses. On this optimistic note, let me take my leave.