How to understand assembler for AVR

    Good evening everyone! I’m conducting my broadcast from a cozy world called “assembler”. I’ll immediately explain that the topic concerns AVR microcontrollers - and I still don’t know whether this post is useful to those who want to use assembler for any other task. The fact is that just a few days ago I started learning assembler from scratch - I need to make one device - and I decided to do everything on it myself. So - one day I realized that it’s absolutely useless to learn assembler! Assembler can only be understood! That is, for all those who want to program in assembler, I strongly recommend that you take a detailed look at how the microcontroller PHYSICALLY works, and then study the intricacies of the commands.
    So, I’m probably going to start a short series of articles in which from the very beginning I’ll tell you exactly how I understood these or those things in assembly language - I think for those who don’t understand what an ASM is, I’ll be just such a “translator” with language of those who in this business rummages very well.

    I must say right away that I more or less tasted this topic from the presentation of DIHALT - therefore, these articles will be a kind of translation from a super-duper-assembler-microcontroller language into a language that most people understand. 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 assembler, which I made a couple of days ago, shocked me to the core - and I sat behind DI HALT's articles from 11 pm to 5 am - after which I went to bed happy and happy. I understood the essence of assembly language for microcontrollers.
    How can this be explained even easier? I think you need to start with the very 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. Only English. He lost the argument and pledged to do without question everything that the Russian asks him to.
    2. Assembler is a translator Vasya whose mother is English and the father is Russian. He knows perfectly both English and Russian.
    3.We are the Russian to whom the Englishman came. Well, that is, we are us =) At the same time, we perfectly know the Russian language and (!!!) a little English - very little, with a dictionary.
    Imagine this situation - an Englishman is sitting in your room on a chair. And you sit at your computer and read this post, when suddenly you have a window open! That's bad luck! The wind is blowing, the curtain has turned into a sail ... It would be nice to close it! But that's how lazy it is to get up from a chair, remove your feet from the system, push them into slippers, put down a mug of coffee (beer) and go to fight with the elements. And then you suddenly realize that in our room there is an embarrassed Englishman, which is the time to drive! And you say to him so sweetly, "Man! Close the window, please, and then you can sit down on a chair again! ” and he sits, looks at you in surprise and does nothing! Of course you can slander them for soup - but then he still will not understand you! Then you call your friend-translator Vasily - he comes, and sits down next to the Englishman in 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 and closes the window, and then comes and sits down in a chair.
    At this point, you just need to understand the role of assembler in this "We-Assembler-Controller" chain.
    That is, how would everyone understand that such an assembler? Then read on.

    So, imagine this situation. You say to Vasya - “Listen, in short, this is the case — I forgot the calculator at home, divided 56983 by 2 and tell Steve to press his fists so many times” and Vasya counts and says to Steve in English “Push your fists 28,491 times” on the calculator This is called the “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 say to Vasya “Tell Steve to wriggle out 28,491 times” and Vasya simply translates your words into English. This is called OPERATOR

    Everything is simple - there is a directive and there is an operator. The operator is your direct indication of what to do to 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, tells Steve something.

    Now we will torment the Englishman regularly! But first you need to get to know our translator Vasya better. You need to know the following - Vasya always obeys you implicitly - what he was told is what he does. Vasin’s calculator does not have decimals - if you look at the example with push-ups, then 56983 \ 2 = 28491.5 - but Vasya’s everything decays off after the decimal point - and he sees only an integer - it doesn’t matter if it has 28491.000001 or 28491.9999999 there - for Vasya 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 is shy to push up twenty-eight thousand times. They told him - Vasya translated. And not only translated - but also forced to do what you asked.

    Actually that's all for now. In the next post we will dig deeper - for now, just enough to understand this. Just imagine this situation and understand what's what, who plays what role and how the directive differs from the operator.
    And then we will try to call everything by their proper names and roughly estimate how the assembler works with the microcontroller as an adult.

    Also popular now: