📜 ⬆️ ⬇️

Assembler for beginners

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

image

I will say right away that I personally assemble not under a PC, but under microcontrollers. But this is not a big deal, because (unlike AVR microcontrollers) the command system of these microcontrollers with a PC is extremely similar. Yes, and, in fact, an assembler in Africa and an assembler.
')
Of course, I don’t set myself the goal of describing everything in this article from beginning to end. Fortunately, an unimaginable number of literature has been written on the assembler. And yes, my experience may differ from the experience of other programmers, but I think it is not superfluous to state the basic concept of this issue in my understanding.

To begin with, I will calm inquisitive recruits: assembler is not at all difficult, contrary to stereotypical opinion. Simply, it is closer to the "land", I mean the architecture. In fact, it is very simple, if you grasp the main idea. Unlike high-level languages ​​and a variety of specialized programming platforms (I understand everything like C ++, MatLAB and other similar things where programming skills are required), the teams did one or two and miscalculate. At first, even when I needed to calculate the double integral, this task caused only bewilderment: how could such a procedure be performed with such a meager number of operations? After all, figuratively speaking, in an assembler, you can only add, subtract and shift numbers. But with the help of the assembler, you can perform arbitrarily complex operations, and the code will come out extremely easy. Here, even for an example, you need to light the LED that is connected, for example, to the zero contact of port number 2, you just write:
bset p2.0
And, as they say, no problem. Should I turn on four pieces connected in series right away? Yes, easily:
mov P2, # 000fh
Yes, here I mean that the novice fighter is already familiar with at least the number systems. Well, at least with a decimal. ;)

So, in order to succeed in assembling, you should understand the architecture (in my case) of the microcontroller. This time.

By the way, one of the sore points 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 the key pain points: interruptions. The thing is not complicated, but at the beginning (for some reason) difficult for perception.

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

So, the second key to success is an extensively written and well thought out algorithm. I strongly recommend not to sit down right behind the device and write a program. Nothing sensible you do not write on the go. These are two.

Actually, I would like to write as Fandorin: “This is t-t-three” ... But, I'm afraid, for now you can stop at this. Although I would like to add a few recommendations and gingerbread.

Summing up my somewhat confused monologue, the key points in programming in assembler are the knowledge of architecture and the connected construction of thoughts. Of course, it is not necessary to immediately rush into studying literature describing the insides of the same PC, but the general idea (I repeat, at least for a start) will be very necessary.

And now the promised gingerbread! Here I am crucifying about some incomprehensible assembler, but what is really good about it? Yes, a lot of things! First, of course, you do not need to memorize a lot of commands, libraries used, and other related crap. Just a couple of teams and, consider, you are fully armed. Secondly, due to the extreme proximity to machine codes, you can do almost anything your heart desires (as opposed to high-level languages)! Thirdly, the assembler code, due to the maximum brevity in the formulations, is performed extremely quickly.

In general, solid pluses. On this optimistic note, allow me to bow out.

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


All Articles