Machine language is a low level language

Programming languages ​​- How do I tell my computer


As most of you should already know, every microcontroller and every microprocessor needs a program to work. This must first be created by a developer. Everyone who deals with controllers, such as the ATMega 8 on these pages, must first create a program so that it does something.


At the beginning of the computer age, programs were punched on punch cards, which were then read out and processed by the calculating machine. Later you could use strips of paper, which was a simplification. However, these systems were only used to program the computer in machine language. Machine language is the language that every controller and processor understands directly. The commands in machine language are very small instructions, which are represented by a combination in binary code. A program that e.g. performs a small addition could look like this:


Command in binary code


0001 0011Load value 3 into working register
0010 0010Add the value 2 to it
0011 0001Output result to device 1


Now nobody can memorize such a jungle of numbers. Therefore, abbreviations have been considered for the individual binary sequences, which roughly describe the commands. So our program could look like this:




LD 3

Load value 3 into working register


Add the value 2 to it


Output result to device 1


Here we basically have the first programming language, the assembly language. With this you can write reasonably understandable programs. In order to convert these programs into machine language, however, you now need a translator. The assembler. The assembler turns the instruction series back into the binary series that our processor needs to work.


This form of programming has a decisive advantage. Here you can really get everything out of the processor, as you can completely control it. But precisely this advantage is also a major disadvantage. You can't simply tell the processor, for example, 'Output "temperature too low" on the terminal, but you still have to tell it where, in what form, at what speed and then not as a whole text, but always a character the other. The programmer also has to take care of all the other properties of a processor.


Since assembler programming is very time-consuming and very complex in the long run, so-called high-level languages ​​have been developed which pack the standard tasks of a processor into small modules, so-called routines, and where later only one command is required in a program. "Temperature too low" can then be output using a command such as 'PRINT "Temperature too low"' and the processor outputs the text to the terminal.


So that the CPU does what it is supposed to do with a corresponding instruction, a system is required which converts the instructions from the user into machine language. So a translator. A distinction is made between two large groups:



On the one hand you can use something called an interpreter. Here every command is compiled and looked up in a small library, where the corresponding routine for e.g. 'PRINT' is located in the program memory. This is then called. If the interpreter encounters this instruction again, the interpreter must recognize 'PRINT' again, check where it is located and execute it. Understandably, this procedure takes a lot of time.


Interpreters also have the advantage that they can be programmed 'live'. So you don't have to compile the program and write it into the ROM of the processor after every change to a program. Interpreters were very popular in the big days of home computers with the C64, Amstrad / Schneider CPC, Sinclair Spectrum, etc. These computers would probably never have had such immense success if you had first needed a development system to even get the result of '2 +3 'to be able to calculate.




If you want to write faster programs but don't want to mess with assembler, you still have the option of using a compiler. In contrast to interpreters, compilers do not work permanently on a computer system, but are only executed when they are needed.


In the case of a compiler, our 'PRINT' instruction is replaced by a jump instruction in the final machine program. This eliminates the need to repeatedly recognize and look up the corresponding instruction. The final machine program, which was created by the compiler, then consists for the most part of a series of jump instructions. Only the command library is added to the machine program (linked) and the program can take up its service in the controller. It then works a lot faster than an equivalent program that is executed by an interpreter.


Adding libraries also has an immense advantage. This makes it possible to add libraries that are intended for special tasks. If the controller is to control a certain display, for example, a library is simply integrated which contains the functions of this display.


There are several different compilers on the market for various programming languages. Which compiler you use largely depends on your personal taste. I would like to briefly introduce some programming languages ​​here.



The most common programming languages



The programming language with the greatest popularity is probably Basic (Beginners All Surpose Instruction Code). As the name suggests, Basic is a very easy programming language to learn. Most commands are almost self-explanatory. This was probably also the reason why most home computers had Basic in an interpreter version 'on-board'.


The most popular basic version of the AVR is BASCOM, which is also used on these pages. BASCOM provides a compiler that you quickly notice when developing. Each time before the program can be transferred, the program must first be compiled.



Dim Cnt


For Cnt = 1 To 10

Print "Pass:"; Cnt





Pascal is only available in compiler versions. Due to the structure, interpreters are not even possible. With Pascal you are automatically stopped and programmed in a structured way. This 'constraint' also makes it possible for a very compact code to be generated.



Procedure CountLoop

Var Cnt: byte;


For Cnt: = 1 To 10 Do


Write ('Pass:', Cnt);






The language C is also very widespread. There are also various C variants on the AVR. Most of the programs on the PC were also developed in this language. The structure of C is similar to Pascal, but it may seem a bit 'cryptic' to beginners due to the fact that the language works a lot with special characters.



Void CntLoop (Void)


Byte Cnt;


for (Cnt = 1; Cnt <= 10; Cnt ++)


Printf ('pass:', cnt);