Computer
Architecture
Computer
Languages
Stefan Verbruggen
1
Inhoud
•Computer Languages
• Overview
• What is a computer language?
• Classification
• Low Level (1GL, 2GL)
• Mid Level (2GL, 3GL)
• High Level (3GL, 4GL, 5GL)
• Compiling & Linking
• Static versus dynamic
• Cross compilation
• Handson stuff
2
Computer Languages
3
“A few“ Computer Languages
• FORTRAN (formula translation, 1957)
• C (predecessor was “B programming language”, 1972) => primary intended usage: “writing operating systems”
• ANSI-C (American National Standards Institute C, 1983)
• COBOL (common business oriented language, 1959) => Finance
• SQL => databases
• BASIC (beginners’s all-purpose symbolic instruction code, mid-1960s)
• Pascal (1970) => educational
• C++ (mid-1980s)
• C# (C-sharp, 2000)
• Java (early 1990s)
• Visual Basic => Visual Basic .NET (2002)
• Python (1991)
• Perl (practical extraction and reporting language, late 1980’s) => sys admin
• (La)Tex (1977) => Tekst formatting by programming
• Postscript => printer language
• HTML (1980s)
Dennis Ritchie, father of C and UNIX
• XML
• …
[Link]
4
What is a Computer Language?
• Generally, we use languages like English, Dutch, French, etc., to make communication
between two persons. That means when we want to make communication between two
persons we need a language through which persons can express their feelings.
• Similarly, when we want to make communication between user and computer or between
two or more computers we need a language through which user can give information to the
computer and vice versa. When a user wants to give any instruction to the computer the user
needs a specific language and that language is known as a computer language.
• The user interacts with the computer using programs and those programs are created using
computer programming languages like C, C++, Java, etc.,
• Every computer programming language contains a set of predefined words and a set of rules
(syntax) that are used to create instructions of a program.
• Computer languages are the languages through which the user can communicate with the
computer by writing program instructions.
5
Computer Languages
Classification
Over the years, computer languages have been evolved from Low-Level to High-Level Languages.
In the earliest days of computers, only Binary Language (0’s and 1’s) was used to write programs.
The computer languages can be classified as follows...
[Link]
6
Low-Level Language: Machine
Language
• Low-Level language is the only language which can be understood by the computer.
Binary Language is an example of a low-level language. Low-level language is also
known as Machine Language. The binary language contains only two symbols 1 &
0. All the instructions of binary language are written in the form of binary numbers 1's
& 0's. A computer can directly understand the binary language. Machine language is
also known as the Machine Code.
• As the CPU directly understands the binary language instructions, it does not require
any translator. CPU directly starts executing the binary language instructions and
takes very less time to execute the instructions as it does not require any translation.
Low-level language is considered as the First Generation Language (1GL).
• These instructions are specific to a machine and therefore will differ from machine to
machine.
7
Low-Level Language: Machine
Language
Advantages
• A computer can easily understand the low-level language.
• Low-level language instructions are executed directly without any translation.
• Low-level language instructions require very less time for their execution.
Disadvantages
• Low-level language instructions are very difficult to write if not impossible.
• Low-level language instructions are machine-dependent, that means a program written for a
particular machine does not execute on another machine. Machine code for an AMD-X64 will
not run on an Apple M2 or a RaspBerry PI4 (both ARM based). Meaning these are not portable.
• In low-level languages, there is more chance for errors and it is very difficult to find errors,
debug and modify.
8
Low-Level Language: Machine
Language
9
Produced with a Trial Version of PDF Annotator - [Link]
Mid Level languages
C programming
• These are programming languages which exhibit features of both high level and low level
programming languages.
• The C programming language is a good example of a mid-level programming language since it has
features of both.
• We can also place assembly language in this category since it is also readable and can be coded
and maintained relatively easily by an expert in a specific processor architecture.
10
Produced with a Trial Version of PDF Annotator - [Link]
Low or Middle-Level Language:
Assembler
• This is a better (readable) version of machine language whereby instead of using raw binary sequences to
write instructions, we use mnemonics.
• These mnemonics are then translated to machine language specific to a processor architecture by an
assembler.
• Assembly code has the best of both worlds, it is fast and can be read and understood and also communicates
with the hardware directly.
• Low-level Assembly language is considered as a Second Generation Language (2GL).
11
Low or Middle-Level Language:
Assembler
Pros of Assembler languages
• They are in direct communication with hardware.
• No need for compilers or interpreters since code is ready to be executed by a
processor. Assembler is needed !
• Provides better use of memory and processing power.
• They provide direct manipulation of computer registers and storage.
• Programs developed with low level programming languages are fast and
memory efficient.
12
Low or Middle-Level Language:
Assembler
Cons of Assembler languages.
• Difficult to write, read, debug or maintain.
• They are processor architecture specific (=machine-dependent) and therefore
a programmer needs to have a specific knowledge of particular processor
architecture in order to write code for it.
• Coding in low level languages exposes one to a lot of errors.
• Programming in a low level language results in poor programming productivity.
• Low level programs are not portable.
13
Low or Middle-Level Language:
Assembler
14
High Level Language
• High-level language uses format or language that is most familiar to users.
• The instructions in this language are called codes or scripts.
• The computer needs a compiler (C) or an interpreter (Perl) to convert a high-
level language program to machine level language.
• Other examples include C++, Python, Java, etc.
• It is easy to write a program using high level language and is less time-
consuming.
• Debugging is also easy and is a human-readable language.
• Main disadvantages of this are that it takes a lot of time for execution and
occupies more space when compared to Assembly- or Machine-level
languages.
15
High Level Language
Advantages
• Writing instructions in a high-level language is easier.
• A high-level language is more readable and understandable.
• The programs created using high-level language run on different machines
with little change or no change (just recompile for that architecture).
• Easy to understand, create programs, find errors (debug) and modify.
Disadvantages
• High-level language needs to be translated into low-level language.
• High-level language executes slower compared to middle and low-level
languages.
• Occupies more space when compared to Assembly- or Machine-level
languages.
16
High Level Languages:
Generations
Third-Generation Languages (3GL)
• C, Pascal, FORTRAN, COBOL, C++, Java, Visual Basic, JavaScript, …
Fourth-Generation Languages (4GL)
• These are languages that consist of statements that are similar to statements
in the human language.
• These are used mainly in database programming and scripting.
• Examples of these languages include Perl, Python, Ruby, SQL, and
MatLab(MatrixLaboratory).
Fifth Generation Languages (5GL)
• These are the programming languages that have visual tools to develop a
program.
• Examples of fifth-generation languages include Mercury, OPS5, and Prolog.
17
Third-Generation Language
• The third generation is also called procedural language /3 GL.
• It consists of the use of a series of English-like words that humans can understand easily,
to write instructions.
• For execution, a program in this language needs to be translated into machine language
using a Compiler/ Interpreter.
• Examples of this type of language are C, PASCAL, FORTRAN, COBOL, etc.
Advantages :
• Use of English-like words makes it a human-understandable language.
• Lesser number of lines of code as compared to 1th and 2th generation languages.
• Same code can be copied to another machine & executed on that machine by using a
compiler-specific to that machine.
Disadvantages :
• Compiler/ interpreter is needed.
• Different compilers are needed for different machines.
18
Third Generation Language:
example C
19
Fourth Generation Language
• The fourth-generation language is also called a non – procedural language/ 4GL.
• It enables users to access databases.
• Examples: SQL, Foxpro, Focus, etc.
• These languages are also human-friendly to understand.
Advantages :
• Easy to understand & learn.
• Less time is required for application creation.
• It is less prone to errors.
Disadvantages :
• Memory consumption is high.
• Has poor control over Hardware.
• Less flexible.
20
Fifth-Generation Languages
• The fifth-generation languages are also called 5GL.
• It is based on the concept of artificial intelligence.
• We make computers to learn to solve any problem.
• Parallel Processing & superconductors are used for this type of language to make
real artificial intelligence.
• Examples: PROLOG, LISP, etc.
Advantages :
• Machines can make decisions.
• Programmer effort reduces to solve a problem.
• Easier than 3GL or 4GL to learn and use.
Disadvantages :
• Complex and long code.
• More resources are required & they are expensive too.
21
Computer Languages: Roundup
• The programming languages like C, C++,
Java, etc., are written in High-level language
which is more comfortable for the
developers.
• A high-level language is closer to the users.
• Low-level language is closer to the computer.
Computer hardware can understand only the
low-level language (Machine Language).
• The program written in the high-level
language needs to be converted to low-level
language to make communication between
the user and the computer.
• Middle-level language is not closer to both
user and computer. We can consider it as a
combination of both high-level language and
low-level language.
22
3GL Languages: compiling &
linking
When programmers talk about creating programs, they often say, "it compiles
fine" or, when asked if the program works, "let's compile it and see".
This colloquial usage might later be a source of confusion for new programmers.
Compiling isn't quite the same as creating an executable file! Instead, creating an
executable is a multistage process divided into two components: compilation
and linking.
In reality, even if a program "compiles fine" it might not actually work because of
errors during the linking phase. The total process of going from source code files
to an executable might better be referred to as a build.
23
3GL Computer Languages: compilation
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and
the creation of an 'object' file.
This step doesn't create anything the user can actually run. Instead, the compiler
merely produces the machine language instructions that correspond to the
source code file that was compiled.
For instance, if you compile (but don't link) three separate files, you will have
three object files created as output, each with the name <filename>.o or
<filename>.obj (the extension will depend on your compiler).
Each of these files contains a translation of your source code file into a machine
language file -- but you can't run them yet! You need to turn them into
executables your operating system can use. That's where the linker comes in.
24
3GL Computer Languages: linking
Linking refers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will
complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for
a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the
compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look
at multiple files and try to find references for the functions that weren't mentioned.
You might ask why there are separate compilation and linking steps. First, it's probably easier to implement things that way.
The compiler does its thing, and the linker does its thing -- by keeping the functions separate, the complexity of the program
is reduced. Another (more obvious) advantage is that this allows the creation of large programs without having to redo the
compilation step every time a file is changed. Instead, using so called "conditional compilation", it is necessary to compile
only those source files that have changed; for the rest, the object files are sufficient input for the linker. Finally, this makes it
simple to implement libraries of pre-compiled code: just create object files and link them just like any other object file. (The
fact that each file is compiled separately from information contained in other files, incidentally, is called the "separate
compilation model".)
To get the full benefits of condition compilation, it's probably easier to get a program to help you than to try and remember
which files you've changed since you last compiled. (You could, of course, just recompile every file that has a timestamp
greater than the timestamp of the corresponding object file.) If you're working with an integrated development environment
(IDE) it may already take care of this for you. If you're using command line tools, there's a nifty utility called make that comes
with most *nix distributions. Along with conditional compilation, it has several other nice features for programming, such as
allowing different compilations of your program -- for instance, if you have a version producing verbose output for debugging.
25
3GL Languages: compiling &
linking
Knowing the difference between the compilation phase and the link phase can
make it easier to hunt for bugs:
Compiler errors are usually syntactic in nature -- a missing semicolon, an extra
parenthesis.
Linking errors usually have to do with missing or multiple definitions. If you get an
error that a function or variable is defined multiple times from the linker, that's a
good indication that the error is that two of your source code files have the same
function or variable.
26
Linking: static versus dynamic
27
Produced with a Trial Version of PDF Annotator - [Link]
Linking: static versus dynamic
via een pad/verwijzing de executable
doen (de library moet aanwezig zijn op je
pc anders werkt het niet)
A static linked program includes every library necessary to run, results in larger executable file.
With dynamic linking the library [Link] must exist on every machine where you want to run the program.
28
Linking: static versus dynamic
Sources of libraries
• Standard Libraries
• Third Party Libraries (free or $$$)
• Libraries created by ourselves
Reasons for using Shared or Dynamic linked libraries
• To avoid producing big executables files that eat a lot of storage space
• To save memory while running multiple applications that use the same
dynamic linked libraries. These are only loaded once in memory (when the
first program that dynamically linked them uses them). So a program that calls
a function in a dynamic linked library that is not yet in memory, is slightly
slowed down by the load process of the entire library.
29
Linking: static versus dynamic
Disadvantages of shared or dynamic libraries
• Dependency hell or DLL hell
• Difficult to distribute and install dynamically linked applications
• Entire library must be loaded into memory during run-time
• CONTAINERS come in handy here!
30
Produced with a Trial Version of PDF Annotator - [Link]
alle libraries
staan erop
31
32
Cross compiling
A cross compiler is a compiler capable of creating executable code for a platform
other than the one on which the compiler is running.
For example, a compiler that runs on a PC (x86_64 or i686) but generates code
that runs on an Android smartphone is a cross compiler.
Why Cross Compiling exists ?
• A cross compiler is useful to compile code for multiple platforms from one
development host.
• Direct compilation on the target platform might be infeasible, for example on
embedded systems with very limited computing resources (few memory, slow
CPU, ...).
[Link]
33
Produced with a Trial Version of PDF Annotator - [Link]
Cross compiling: sample
Example: building a program on an x86_64 running Linux to run on a Raspberry
PI (ARM aarch64) running Raspbian 64-bit .
[Link]
34
Cross compilation: 2th example
Cross-compile the C program “hello world !” on an x86_64-machine for an
IBM 64-bit Big Endian PowerPC machine running openSUSE.
[Link]
35