Programming languages (Machine language, assembler)
Just as languages serve as a means of communication between human beings, there are
languages that enable communication between each other and computers. These languages
They allow expressing the instructions that the programmer wants the computer to execute.
The main types of languages used today are three:
Machine language
Low-level language (assembly)
High-level languages
Machine languages
Machine language refers to the instructions given directly to the computer.
using a series of binary digits or bits, represented by the numbers 0 and 1 that
they specify an operation. Although this language is what the computer understands, it is very
difficult to handle in human communication. The instructions in machine language
depends on the computer hardware and, therefore, will vary from one computer to another.
another.
Low-level languages (assembly)
Low-level languages are easier to use than machine languages, but just like
that they depend on the particular machine. The quintessential low-level language is the
assembler (assembly language). The instructions in assembly language are known
as mnemonics.
For example, typical mnemonics for arithmetic operations are:
ADD
SUM
A typical addition instruction would be:
ADD M, N, P
This instruction could mean "add the number contained in the memory position M to
number stored in memory position N and place the result in the position of
Memory P." It is obviously much easier to remember the previous instruction with a
mnemonic that corresponds to its equivalent in machine code.
IB
A program written in assembly language cannot be executed directly by the
computer (in this it essentially differs from machine language) but requires
a phase of translation into machine language.
The original program written in assembly language is called source program and the
A program translated into machine language is known as an object program, directly.
understandable by the computer.
The translator from source programs to object is a program called assembler.
existing in almost all computers.
NOTE: The assembler program, responsible for carrying out the translation, should not be confused.
of the source program written in machine language, with the assembly language
language), programming language with a defined structure and grammar.
Assembly languages have the advantage over machine languages of their greater
ease of coding and, in general, its calculation speed.
The most notable drawbacks of assembly languages are:
Total dependence on the machine, which impedes the transportability of the programs.
(possibility of running a program on different machines).
The training of programmers is more complex than that of
high-level programmers, as it requires not only programming techniques but also
the knowledge of the interior of the machine.
Today, assembly languages have very limited applications in the
application programming and focuses on real-time applications, process control
and electronic devices, etc.
Importance of assembly language
The importance of assembly language lies primarily in the fact that it works directly
with the microprocessor; therefore, one must understand its internal operation,
it has the advantage that any type of programs can be made in it that in the
high-level languages cannot perform it. Another point would be that programs in
Assemblers take up less space in memory.
Advantages and disadvantages of Assembly Language
Advantages
SpeedAs it works directly with the microprocessor when executing a program,
Well, since this language is the closest to the machine, the computer processes it more.
quick.
[Link] [Link] assembly program doesn't take up much space in
memory because it does not need to load libraries and others like high-level languages
FlexibilityIt is flexible because everything that can be done with a machine can be done
in the assembly language of this machine; high-level languages have in one way or another
limiting forms to fully exploit the machine's resources. In other words,
In assembler, specific tasks can be performed that cannot be done in a high-level language.
they can carry it out because they have certain limitations that do not allow them to do so
Disadvantages
Programming time As it is a low-level language, it requires more instructions.
to carry out the same process, in comparison with a high-level language. On the other hand,
requires more care from the programmer, as it is prone to errors
logic is reflected more strongly in execution.
Large source programs .For the same reasons that time increases, so do the
source programs; we simply require more primitive instructions to describe
equivalent processes. This is a disadvantage because it complicates the maintenance of the
programs, and again reduces the productivity of programmers.
Danger of unexpectedly affecting resources That every mistake we could make, or every
risk that we may have, we can affect the resources of the machine, program in this
The most common thing that can happen is that the machine gets stuck or restarts.
Because with this language it is perfectly possible (and easy) to execute sequences of
invalid instructions, which usually do not appear when using a high-level language.
Lack of portability. Because for every machine there exists an assembler language; for that reason,
evidently it is not an appropriate selection of language when we want to code in a
machine and then carry the programs to other operating systems or models of
computers.
Relationship of assembly language with the internal components of the processor
In the memory, information is stored in special cells called registers which
they have a high level and a low level.
Arithmetic and logic unit is responsible for performing as its name indicates
arithmetic and logical operations.
Control unit is responsible for coordinating that the other components execute the
operations correctly.
Internal bus is the channels through which the information that the machine is going to process passes.
input) or processed (output bus).
General usage records
AX = Accumulator register, divided into AH and AL (8 bits each). - Intervenes in the
arithmetic and logical operations, after the operation it yields a result.
BX = Base register, divided into BH and BL. - It is used in data transfers between memory.
and the processor.
CX = Counter register, divided into CH and CL. - It is used as a counter in loops (LOOP), in
operations with strings (REP), and in shifts (CL).
DX = Data register, divided into DH and DL. - It is used in multiplication operations.
division along with Ax and in input and output operations of ports, its lower half DL
it contains the number of ports.
State Records
There are nine indicators of a bit in this 16-bit register. The four most significant bits
are undefined, while there are three bits with determined values: bits 5 and 3 always
zero is worth zero and bit 1 always equals one.
CF (Carry Flag, bit 0): If it is 1, it indicates that there was a 'carry' (in the case of addition) or a 'borrow' (in the case of subtraction).
case of subtraction). This indicator is used by instructions that add or subtract numbers that
they occupy several bytes. The rotation instructions can isolate a bit from memory or from a
registering it in the CF.
PF (Parity Flag, bit 2): If it is one, the result has even parity, that is, an even number of
bits a 1. This indicator can be used to detect errors in transmissions.
AF (Auxiliary carry Flag, bit 4): If it is 1, it indicates that there was 'carry' or 'borrow' from the nibble.
(four bits) least significant to the most significant nibble. This indicator is used with the
decimal adjustment instructions.
ZF (Zero Flag, bit 6): If this indicator is 1, the result of the operation is zero.
SF (Sign Flag, bit 7): Reflects the most significant bit of the result. Like negative numbers
they are represented in two's complement notation, this bit represents the sign: 0 if it is
positive, 1 if it is negative.
TF (Trap Flag, bit 8): If it is 1, the processor is in single-step mode. In this mode, the CPU
automatically generates an internal interrupt after each instruction, allowing
inspect the results of the program as it executes instruction by instruction.
IF (Interrupt Flag, bit 9): If it is 1, the CPU recognizes external interrupt requests. If it is 0,
such interruptions are not recognized
DF (Direction Flag, bit 10): If it is set to 1, string instructions will experience 'auto-decrement'.
this means that the strings will be processed from the highest memory addresses to the lowest
drops. If it is worth 0, there will be 'auto-increment', which means that the strings will be processed
from left to right
OF (Overflow flag, bit 11): If it is 1, there was an overflow in a signed arithmetic operation.
this is, a significant digit was lost because the size of the result is greater than the
size of the destination.
Relationship between binary code and assembly language
In binary code, zeros and ones are used, while assembly language is a
collection of mnemonic symbols that represent: operations, symbolic names,
operators and special symbols.
The relationship between these two languages is that binary is the language that the machine
understand and the assembler is closer to this language.
Memory management: Addressing (internal and external)
The memory management depends on which processor the machine has, among which
the following are mentioned:
Program Memory
External Data Memory
Internal Data Memory
Records of Special Functions
Bit Memory.
The Program Memory space contains all the instructions, data, tables and
character strings used in programs. This memory is addressed
primarily using the 16-bit register called Data Pointer. The maximum size of the
The program memory is 64 Kbytes.
The External Data Memory contains all the variables and data structures that do not
they fit in the internal memory of the Microprocessor. This memory is addressed
mainly due to the 16-bit Data Pointer register, although it can also be addressed
an External Data Memory bank of 256 bytes using the first two registers of
general purpose.
The space of Functional Internal Data Memory is the data memory most
important, as this is where four general-purpose registry banks reside; the
stack of the program; 128 bits of the 256 bits of a bit-addressable memory area
and all the variables and data structures operated directly by the program. The
The maximum size of the Internal Data Memory is 256 bytes.
Contains a space for the so-called Special Function Registers intended for
the input/output ports, timers, and serial port of the integrated circuit. These
Registers include the Stack Pointer; the program status word register and the
Accumulator. The maximum number of Special Function Records is 128.
All Special Function Registers have addresses greater than 127 and are located in
the upper 128 bytes of the Internal Data Memory. These two areas of the Memory
Data internals differ by the addressing mode used to access them.
Special Functions Records can only be accessed using the mode of
direct addressing, while the upper 128 bytes can only be accessed with
the Indirect addressing mode.
On the other hand, the Bit Memory space is used to store variables and flags of a
bit. The maximum size of the Bit Memory is 256 bits, 128 of the bits share their
space with 16 bytes from the Internal Data Memory and the other 128 bits make it
with the Special Functions Records.
Language translators
Language translators are programs that in turn translate source programs.
written in high-level languages to machine code.
Translators are divided into:
Compilers
Interpreters
Interpreters
An interpreter is a translator that takes a source program, translates it, and then
execute (said program through the computer performs a specific task).
A language that supports an interpreter-type translator is called an interpreted language.
BASIC is the ultimate interpreted model.
Source programs in BASIC are written with the help of a program called an editor.
which is usually included in the interpreter program.
Compilers
A compiler is a program that translates source programs written in high-level languages.
level to machine language.
Programs written in high-level languages (in the language editor) are called
source programs and the translated program object program or object code. The compiler
translate (sentence by sentence) the source program.
Typical compiled languages are: PASCAL, COBOL, C.
Phases of compilation
Compilation is the process of translating source programs into object programs.
The object program obtained from the compilation has not been normally translated to code.
machine code but to assembler. In order to obtain the actual machine program, a
program called assembler or linker. The assembly process leads to a
directly executable program in machine language
For example:
The execution process of a C++ Program has the following steps:
Source code writing with an editor (program that allows a computer
act in a manner similar to an electronic typewriter) and save it to a device of
storage (a disk).
Load the source program into memory.
Compile the program with the C++ compiler.
Check and correct compilation errors (list of errors).
Obtaining the object program.
The assembler obtains the executable program.
The program is executed and if there are no errors, its output will be obtained.