0% found this document useful (0 votes)
8 views70 pages

The Principle of Compilation and Assembler

The document explains how computers work, detailing the roles of input, processing, memory, and output, as well as components like the CPU, control unit, and ALU. It also covers the functions of compilers and assemblers, including the processes of lexical, syntax, and semantic analysis, along with code generation and optimization. Additionally, it discusses the importance of binary data and transistors in computer operations.

Uploaded by

nadushlyth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views70 pages

The Principle of Compilation and Assembler

The document explains how computers work, detailing the roles of input, processing, memory, and output, as well as components like the CPU, control unit, and ALU. It also covers the functions of compilers and assemblers, including the processes of lexical, syntax, and semantic analysis, along with code generation and optimization. Additionally, it discusses the importance of binary data and transistors in computer operations.

Uploaded by

nadushlyth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

ASMA BERRADJA

MAHI AYA
HOW COMPUTER WORKS
HOW COMPUTER WORKS

WHAT IS THE COMPILER


HOW COMPUTER WORKS

WHAT IS THE COMPILER

WHAT IS THE ASSEMBLER


HOW COMPUTER WORKS

WHAT IS THE COMPILER

WHAT IS THE ASSEMBLER

WHY COMPUTER UNDERSTAND BINARY DATA


HOW COMPUTER WORKS

WHAT IS THE COMPILER

WHAT IS THE ASSEMBLER

WHY COMPUTER UNDERSTAND BINARY DATA

SUMMARY
HOW COMPUTER WORKS
5
3 7
1 ARITHMETIC LOGIC
UNIT (ALU) STORAGE AND
INPUT MEMORY DATA MANAGEMENT

2 6
4 8
PROCESSING OUTPUT
CONTROL UNIT CONTROL AND
COMMUNICATION
INPUT

The process begins when you provide input to the computer, which
can come from various sources such as:

keyboard mouse microphone


PROCESSING
The central processing unit (CPU) is the brain of the computer. It interprets and
executes instructions. It fetches data and instructions from memory, performs
calculations,
MEMORY
Computers have two main types of memory

RAM Secondary storage devices

hard drives SSDs


CONTROL UNIT

It is a component of the CPU that manages the execution of instructions.


ARITHMETIC LOGIC UNIT

The ALU is a part of the CPU that performs arithmetic and logical operations
OUTPUT

Once the CPU processes the data, the results are sent to an output device.

printer

monitor speakers
STORAGE AND DATA
MANAGEMENT
Data that needs to be retained is stored on long-term storage devices.Data
can be organized into files and directories for easy retrieval
CONTROL AND COMMUNICATION

The computer's operating system manages various processes . It also


facilitates communication between software, hardware, and the user
5
3 7
1 ARITHMETIC LOGIC
UNIT (ALU) STORAGE AND
INPUT MEMORY DATA MANAGEMENT

2 6
4 8
PROCESSING OUTPUT
CONTROL UNIT CONTROL AND
COMMUNICATION
WHAT IS THE COMPILER
Assembly
Language

High-Level
Programming Machine Language
Languages

COMPUTER
LANGUAGES
High-Level
Programming
Languages

High-level programming
languages are designed for human
readability and ease of use.
EXAMPLE

Here's how you can perform the addition of 15 and 11 in the C


programming language:
Assembly
Language

High-Level
Programming Machine Language
Languages

COMPUTER
LANGUAGES
COMPILER

The purpose of a compiler is to convert human-readable source code into a format that a
computer can understand and execute.
source code

lexical analysis

syntax analysis

semantic analysis
ERROR
SYMBOL TABLE
PROCESSING
MANAGEMENT
intermediate code
generation

code optimisation

code generation front end

target code
back end
lexical analysis
lexical analysis

It converts the High level input program into a sequence of Tokens.


lexical analysis

token

a,b,c =,+,-
Identifiers operators

int,printf (),{},;
keywords special symbols
lexical analysis

specifications of token
Alphabets
lexical analysis

specifications of token
String
lexical analysis

specifications of token
Special symbols
lexical analysis
LEXEMES TOKENS
lexical analysis

printf Printf
EXAMPLE

a = b + c * 10

a = b + c * 10

<symbol a> a,b,c int,printf


<’=’> Identifiers keywords
<symbol b>
<’+’>
=,+,- (),{},;
<symbol c>
operators special symbols
<’*’>
<value 10>
EXAMPLE

a = b + c * 10
a = b + c * 10

<id,symbol a>
a,b,c int,printf
<op,’=’>
Identifiers keywords
<id,symbol b>
<op,’+’>
<id,symbol c> =,+,- (),{},;
<op,’*’> operators special symbols

<const,value 10>
syntax analysis
syntax analysis

Syntactic analysis involves analyzing the token sequence to identify the


syntactic structure of the program.
EXAMPLE

x=a+b*c

cfg production rules


EXAMPLE

x=a+b*c
semantic analysis
semantic analysis

Semantic analysis is the stage in which semantic information is


compiled through the parse tree and the construction of a symbol table.
semantic analysis

It checks the syntax analyzer's parse tree.

It verifies the programming language validity of the


code, such as data type compatibility,variable
declaration, initialization, etc.

It also generates a verified parse tree. The annotated


parse tree is another name we give to this tree.
semantic analysis

Semantic Errors:

Type mismatch

Undeclared variables

Reserved identifier misuse


intermediate code
generation
intermediate code
generation
It is a phase in the compilation process .it involves converting the source code
into an intermediate code
THREE-ADDRESS CODE

A statement involving no more than three references(two for operands and one
for result) is known as a three address statement.
THREE-ADDRESS CODE

x, y, and z will have address

x = y op z (memory location). Sometimes


a statement might contain less
than three references but it is
still called a three address
statement.
EXAMPLE

x=a+b*c
code optimisation
code optimisation

Its purpose is to modify the code to run faster and consume fewer resources ,It
deletes any unnecessary lines.
EXAMPLE

code optimisation
code generation
code generation
x=a+b*c lexical analysis

syntax analysis

COMPILER
semantic analysis

intermediate code
generation

code optimisation

code generation
Benefits of Using a Compiler

Portability: Compiled code can be executed on any computer that has the same
processor architecture.

Efficiency: Compiled code is typically more efficient than interpreted code.

Error Detection: Compilers can detect many types of errors in the source code
Assembly
Language

High-Level
Programming Machine Language
Languages

COMPUTER
LANGUAGES
WHAT IS THE ASSEMBLER
assembler
It is system software whitch translate programs written in assembly
language into a machine language.

Assembly Machine
Assembler
Language language
Assembly Language

It is a low-level programming language using mnemonics to represent


machine code instructions.
Types of assembler

ASSEMBLER

Single-pass Multipass
assembler assembler
Types of assembler

Single-pass assembler

conversion of assembly code to machine code in one


go.
Types of assembler

Multipass assembler
pass1: fine all labeles,instructions and calculating corresponding adresses
pass2: convert all the instructions into machine langage format.

symbol table:
store all the informations of assembly
langage data ,variables,instructions
,adresses etc…
How assembler works
DIFFERENCES BETWEEN COMPILER AND ASSEMBLER
WHY COMPUTER UNDERSTAND BINARY DATA
PROCESSING
The central processing unit (CPU) is the brain of the computer. It interprets and
executes instructions. It fetches data and instructions from memory, performs
calculations,
SO,WHAT IS TRANSISTOR!
WHAT IS TRANSISTOR!

A transistor is a fundamental electronic building of a computer.

transistor is what makes


a computer work
it is also a compenent that can hold 2 states.

off on
“0” “1”
SUMMARY
ASMA BERRADJA
MAHI AYA

You might also like