Assembly language and high-level languages: when and why

1986/12/01 Alegria Loinaz, Iñaki Iturria: Elhuyar aldizkaria

First generation computers were programmed in machine language. The second with assembly language. The third and fourth are programmed in high-level language. Those of the quintana generation will be programmed with a language close to natural language.

First generation computers were programmed in machine language. The second with assembly language. The third and fourth are programmed in high-level language. Those of the quintana generation will be programmed with a language close to natural language.

Therefore, to program a current computer it is necessary to master some high-level language (BASIC, FORTRAN, COBOL, PASCAL...) and using this language as a tool, we will draft programs that solve our problems. In any case, on a specific computer, and even more so on a micro, we cannot use any language, but one of those that our computer has implemented in its Operating System.

The use of high-level languages does not exclude machine language and especially assembler language. These options, at least that of assembly, are sometimes very suitable.

The aim of this article is to explain when and for what the assembly language (ASSEMBLER) and higher languages should be used.

Introduction

The commands executed or executed directly by a computer are those written in machine language. Machine language commands are known and executed by the CPU Control Unit. These commands stick to the computer and are relatively simple, each representing a single arithmetic operation or normal logic. The machine language is expressed in binary codes by 0 and 1.

Programming in binary is very heavy, leaving aside the other annoyances. Thus symbolic languages were created, first assembly languages and then higher.

Programs written in symbolic language cannot be run directly. Programs written in machine language can only be run directly. The aim of translators is to overcome this objection.

A translator program takes as data the program written in symbolic language and as a result of its execution creates an equivalent program written in machine language. Therefore, the program that we do when we program it in symbolic language cannot be executed directly, since before executing it we must perform a translation process.

Figure: Functional scheme of the COMPILER.

That is why we said that on a computer you can not program in any language, because to program in a language you need your alarm clock. The translation programs are written in machine language and are part of the Operating System, that is, users should not program them and constitute one of the main parts of the auxiliary software that incorporates the computer.

Types of translators

The program that automatically translates from programming language to another language that the machine directly understands, machine language, is called translator. In translators different types are distinguished; on the other hand, assemblers, to translate assembly language programs, and on the other hand, compilers and interpreters to translate higher languages.

When the compilers translate a program, they get an equivalent program in machine language (called an object program), being prepared to run that object program (see figure 1).

On the contrary, interpreters do not fully translate the source program, but read it orderly, translate and execute it. Therefore, they do not correspond to the 2nd independent phase (translation and execution), since both are unified (see figure 2).

A compiler or interpreter can be used to translate a high-level language. For BASIC, PASCAL and others cases, both compiler and interpreter are usually offered. When the translator is very complex and long, interpretative implementation is not convenient. And to carry out the program, the interpreter has to be all the time in the momory, taking for him a part too large. Therefore, most complex languages use compilers. That is why there are no interpreters for COBOL or FORTRAN, at least in normal computers.

When there are two options to return, which one to choose?, interpretation or compilation?

Before answering this question, we must analyze the two main differences generated by its use:

    When you use a compiler, if a program is fine, your object program can be saved and should not be returned in later executions of that program. On the contrary, the program must be translated into all executions using an interpreter.
  1. When a new program is being developed through the compiler, to test it first the complete program will be returned, then the steps before the correction of the errors obtained will be executed and repeated. If performed through the interpreter, the program can change as the program is run and test at the same time, without wasting time translating the entire program.
Figure: Functional scheme of the INTERPRETER.

So, to answer the previous question, we must differentiate two cases: For the development of a new program, it is ideal to use an interpreter, since the tests generated by the corrections can be done immediately. When the program is tested and works properly, it is best to get an equivalent object program through the compiler and use the object program in all subsequent executions, so the runtime has been lower as it is not necessary to translate.

Therefore, when there are two options for a certain language, the best thing in the development phase is to use the interpreter, but once proven that the program is fine. Using the compiler you will get a program of objects for use in the exploitation phase.

However, it is often not available as the Operating System offers only one. In most microphones only interpreter is offered for the BASIC language. Programs that translate the assembly language are called machihembradores (ASSEMBLY), although similar to compilers. The assemblers, being the corresponding language of origin the assembly language, present a particular characteristic: their translation is very fast when obtaining a single machine order from each spring. Therefore, the translation process is much simpler than that of compilers.

Language characteristics

Regardless of the intrinsic differences in the use of one or another type of translators in a given language, each programming language has its own characteristics that limit its use.

Firstly, programming languages could be classified into two types: high-level language and assembly languages are then compared to the characteristics of both types:

    While the assembly language is linked to the machine, higher languages are universal, that is, a program written with a high-level language can be used on different computers without changes or with few changes. A program written in assembly language is valid only for a specific computer. The assembly language is closely related to machine language, so it is further from the program than high-level language. Therefore, the construction of programs is much easier with a high-level language than with an assembly language, which will cause fewer errors or errors using a high-level language. When we program it with assembly language we know how orders and data are implemented in the machine language or at least perceive it. On the contrary, the use of high-level languages, due to its universal character, prevents the use of the details and advantages of each machine language. Consequently, the object program obtained with an assembly language for the same problem will be faster and will have a smaller memo deposition than that obtained with a higher language.
  • For the handling of some special computer components or operations (mainly to make system calls or to obtain or modify information submitted to the system) it is necessary to use the assembly language. In this case the use of the assembly language is mandatory.
1. Table.- Measures of the sample programs.

For the same reason, programs written in superior language are more understandable and readable than those written in assembly language.

The characteristics of paragraphs a) and b) favor the use of the upper canvases and those of paragraphs c) and d) against. In short, the use of high-level languages generates more universal, easy, reliable and understandable programs, but with slower execution times and with greater memory reception.

Some of the above features will be analyzed with an example. The example presents a program that, once the first thousand prime numbers are calculated, 1000 are written with three different languages: the assembly language, the FORTRAN and the PASCAL (see figure 3). In all three cases, the same algorithm and programming mode (called structured programming) have been followed, implemented in the mini-router called VAX 750.

Tracing the example, program commands written in assembly language are not understood if the VAX 11 computer assembly language is not known. The other two can be understood if FORTAN or PASCAL is known from any computer.

In the assembly language written program, although orders are understood one by one, it is very difficult to fully understand and make some change. In the other two cases, especially PASCAL, the intelligibility of the program is much greater.

In order to give a clearer idea of the characteristics set out in paragraph (c) above, the examples have translated and executed the 3 programs obtaining the results shown in table 1.

Analyzing Table 1 it is observed that using high-level languages are created programs of greater reception and less slowness. Therefore, in this case, the memo part of the programs written in high-level language commands is (approximately) 50% higher than the part corresponding to the assembly language program, reaching 100% for the data. For runtime, the assembly language program is 50% faster than FORTRAN and 100% faster than PASCAL. These measures are quite widespread, although in the case of the adoption of the memori of this example there are too many differences.

In general, it can be said that programs made in high-level language are 50% slower and higher than those made in assembly language.

After seeing and analyzing the above features, the time has come to answer the main question. When to use an assembly language and when a high level?

The answer is now evident. In most cases, high-level languages and assembly language will be used only in the following two cases.

    For the realization of a program or subprogram that manipulates certain components and/or special operations of the computer, in which case the use of the excitation language is essential (see paragraph d)). The time or time of execution is critical. For example, when a program built with a high-level language does not enter memory, if done with a sleeve language it can be introduced. In real-time applications the runtime is critical, so it is worth performing the complete program or the most commonly used subroutines with assembly language.
2. Table. More important programming languages.

However, when we use high-level language, what language to choose? It is not the subject of this article to answer this question, but the following three characteristics will be taken into account for decision making:

see table 2
    Type of application. It is not the same to program the management policy as the scientific application. While in the former, very large amounts of data are handled by simple calculations, in the others the most important and complex thing is the calculation. Therefore, there are languages aimed at scientific calculation (FORTRAN, APL...) aimed at management (COBOL, RPG,...) although others are used in two areas (PL/1, BASIC, PASCAL). Efficiency. Some languages, when designed, focused on this concept. In these cases the greatest importance is the speed of execution, the power, the efficiency... Therefore, compilers are quite large and cannot be implemented on small computers. To this type belong the languages COBOL, FORTRAN and PL/1. Currently, commercially these types of languages are the most used.
  1. Methodology. In recent years, the methodology in software development is becoming increasingly important. Instead of focusing on efficiency, some languages are aimed at building good methodology programs, that is, through these languages you can develop more reliable, structured, simpler, more variable programs. With these languages, cheaper software is obtained, as it is demonstrated that more than half the cost of a program is based on tests and tests. A language of this type is PASCAL, currently the most suitable for learning, since it accustom the student in the programming methodology. The BASIC language, for its part, does not help at all to carry out structured programs and those who learn as first language acquire many bad habits.

Table 1 compares the speed corresponding to a PASCAL program and the speed corresponding to a FORTRAN program. PASCAL's is 25% slower, but as can be seen in Figure 3, the PASCAL program reads better than FORTRAN's. In addition, the PASCAL compiler performs many more checks, so errors are found earlier reducing test time.

The languages mentioned here are conventional, that is, imperatives; they have not mentioned the functional languages (LISP and the like) and explanatory languages (PROLOG) that currently have a great development.

Nor have the languages developed for specific applications (GPSS statistics, SIMULATE simulation, etc.) been mentioned.

Conclusions

Figure: Example program.

The criteria to consider when selecting the programming language are:

    If the problem has to do with computer architecture and the system, most of the time it is mandatory to use the assembly language. If memo taking or runtime is critical, it is ideal to use assembly language. Except for the two previous cases, a high-level language will be used and taking into account the type of application, it will be necessary to decide which concept we give the most importance: efficiency or methodology. Ideally, choose an effective language that drives good methodology, but that does not exist today. However, the latest versions of FORTRAN drive the methodology and achieve structured programs without losing effectiveness. If, once the language was selected, there was a compiler and interpretation to translate the programs, the latter would be used in the tests and, once its suitability was verified, the object program will be used for the exploitation.