Let's see some examples of high-level languages first, and then compare them with low-level languages, which are closer to the computer.
BASIC is an old but still used high-level language. In this language, if we want to write Hello on screen, we would use:
PRINT "Hello"
Other languages, such as Pascal, have a more strict syntax which means that we shall have to type more, but that makes it easier for us to find out errors (we'll see later why):
program HelloUsingPascal;
begin
write('Hello');
end.
The equivalent program written in C language is more difficult to read:
#include
int main()
{
printf("Hola");
}
In more modern languages, such as C#, it takes even more steps to achieve the same result:
public class Example01
{
public static void Main()
{
System.Console.WriteLine("Hello");
}
}
As we have seen, as languages evolve, they are able to help the programmer in more tasks, but on the other side, simple programs tend to be more complex. Luckily, not all the languages follow this rule, and some of them are designed to make simple tasks simple (again). For example, to write something on screen using Python language we would type:
print("Hello")
On the other hand, low-level languages are closer to the computer, less similar to human languages. That makes them more difficult to learn, and errors are more difficult to detect and correct, but in return we can get more execution speed and even reach a higher level of control, that sometimes can not be achieved with other languages.
For example, to write Hello using assembly language of a x86 computer running MsDos we might do as follows:
dosseg
.model small
.stack 100h
.data
hello_message db 'Hola',0dh,0ah,'$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4C00h
int 21h
main endp
end main
It is quite difficult to understand. But that is not what the computer understands yet... only an almost direct equivalent. What the computer can really understand is a sequence of zeros and ones. For example, the commands "mov ds, ax" and "mov ah, 9" (whose meaning we shall not care about) would become the following sequence:
1000 0011 1101 1000 1011 0100 0000 1001
(Note: the colors shown in the above examples are used in some programming environments, so that mistakes in our programs can be easier to find).
No comments:
Post a Comment