📜 ⬆️ ⬇️

How to understand the assembler for AVR

Good evening everyone! I conduct my broadcast from the cozy world, which is called "assembler". Immediately I will explain that the topic concerns AVR microcontrollers - and I still do not know if this post will be useful to those who want to use the assembler for any other task. The fact is that just a few days ago I started learning assembler from scratch - you need to make one device - and I decided to do everything in it myself. So - one day I realized that learning assembler is absolutely useless! Assembler can only understand! That is, to all those who want to program in assembler, I strongly recommend that you go into the microcontroller PHYSICALLY and then learn the subtleties of the commands.
So, I will probably start a small cycle of articles in which I will tell you from the very beginning exactly how I understood certain things in programming in assembly language - I think for those who do not understand what I am, I’ll just be such a “translator” with the language of those who are in this business fumbles very well.

I’ll say right away that I have more or less tasted this topic at the suggestion of DIHALT - therefore, these articles will be a kind of translation from super-duper-assembler-microcontroller language into a language understandable to most people. Well, I hope the gurus will correct me in the course of the play, and if I suddenly explain something wrong, they will correct me.
So, the first conclusions about the assembler, which I made a couple of days ago, shook me to the core - and I sat behind the DI HALT articles from 11 pm to 5 am - after which I went to sleep contented and happy. I understood the essence of programming in an assembler for microcontrollers.
How can this be explained even easier? I think we need to start with the essence.
***
Initially, we will not go into technical details (we will talk about them in the next article) - just imagine that there are 3 characters :
1. The microcontroller is the Englishman Steve, who came to the Russian. He perfectly knows English, but in Russian he does not understand at all - not a single word. English only. He lost the argument and undertook to do everything without any questions that the Russian would ask him.
2. The assembler is the translator Vasya whose mother is English and her father is Russian. He knows perfectly both English and Russian.
3.We are Russian, to which an Englishman came. Well, that is, we are we =) At the same time, we perfectly know the Russian language and (!!!) a little English - just a little, with a dictionary.
***
Imagine such a situation - an Englishman is sitting on a chair in your room. And you sit at your computer and read this post, when suddenly you suddenly opened the window! That is because bad luck! The wind is blowing, the curtain has turned into a sail ... It would be nice to close! But after all, it’s like being too lazy to get up from a chair, take off your legs from a system unit, stuff them into slippers, set aside a mug of coffee (beer) and go to fight the elements. And here you suddenly realize that in our room there is a lost Englishman, which is the time to drive! And you say to him so sweetly, “Friend! Close the window, please, and then you can sit down again on the chair! ”And he sits, looks at you with bewilderment and does nothing! Of course, you can slap on schami - but then he won't understand you anyway! Then you call your translator friend Vasily - he comes and sits next to the Englishman on a chair. And you say - Translate: "Steve, go and close the window, and then sit back in the chair!" The translator translates into English - the Englishman understands and goes to close the window, and then comes and sits on the chair.
At this point, you just need to understand the role of the assembler in this chain "We-Assembler-Controller"
That is, what would assembler understand everything? Then read on.
***

So, imagine this situation. You say to Vasya - “Listen, well, in short, such a thing - I forgot the calculator at home, divide 56983 by 2 and tell Steve to press on his fists so many times” and Vasya counts and says to Steve in English “Push with his fists 28,491 times” This is called "DIRECTIVE" - in other words, the directive is a task for Vasya, the result of which is the action of Steve.

There is another situation - you tell Vasya "Tell Steve to get it pressed 28,491 times" and Vasya just translates your words into English. This is called OPERATOR
')
Everything is simple - there is a directive and there is an operator. Operator - this is your direct indication of what to do Steve - Vasya here only translates your requirement into English. And the Directive is a task for Vasya himself - and Vasya first does what you told him, and then, depending on the result, he says something to Steve.

Now we will torture the Englishman regularly! But first you need to get to know our translator Vasya better. You need to know the following - Vasya always listens to you without question - what he was told was what he did. Vasin calculator has no decimal places - if you look at the example of push-ups, then 56983 \ 2 = 28491.5 - but Vasya chops everything after the comma - and he sees only an integer - and it doesn't matter if there is 28491.000001 or there is 28491.9999999 - for Vasi this is one fig will be 28491 in both cases. Nothing is rounded. More important information about Vasya. Vasya is cruel - he doesn't care that Steve gets worn out twenty eight thousand times. He was told - Vasya translated. And not only translated - but also forced to do what you asked. So if Steve dies by twenty-three thousand five hundred and thirteenth push-ups, then it will be exclusively your fault.

Actually this is all for now. In the next post we will dig deeper - for the time being it is enough just to understand it. Just imagine this situation and understand what is what, who plays what role and how the directive differs from the operator.
And then we will try to call everything with our own names and roughly estimate how the assembler works with a microcontroller for an adult.

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


All Articles