Upload
gavhays
View
1.969
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
12 Software Design and Development
Implementation
TRANSLATION
12 Software Design and Development
Syllabus
Different Methods include: Translation Incremental Compilation Interpretation
Advantages and disadvantages of each method
The translation process.
12 Software Design and Development
Why Study the CPU?
What does the CPU do? Is the brains of the computer. Reads and executes program instructions. Performs calculations and makes decisions
(Processing). Also responsible for the detection of syntax
and run-time errors within programs.
12 Software Design and Development
Why Study the CPU?
Components of the CPU
ALU – The arithmetic logic unit and all arithmetic computations take place , such as addition, multiplications and all comparison operations.
Control Unit – Looks after the fetch-execute cycle to make sure it working effectively.
12 Software Design and Development
Why Study the CPU?
Components of the CPU
Accumulator – A special storage register associated with the ALU which is used to store the results of instructions during processing.
Program Counter – Is a register that holds the address of the next instruction.
Register – A special storage location used for temporary storage of data.
12 Software Design and Development
Hierarchy of Code Translation
Source Code
Assembly Code
Machine Code
Opcode Operand Operand
Instruction Address Data
12 Software Design and Development
What is Machine Code?
Is the language of a computer system and that of the CPU.
Known a the binary system. Each computer instruction is a string of binary
digits.
E.G. 100100 100010101100100111111
12 Software Design and Development
Fetch-Execute Cycle
1. Fetch (Where to Go?) Instructions are fetched from main memory. The location of the next instruction is stored within
a program register called the Program Counter.
12 Software Design and Development
Fetch-Execute Cycle
2. Decode (What to do?) Separation of the machine code into an opcode
and two operands take place. The opcode is then loaded into the instruction
register.
12 Software Design and Development
Fetch-Execute Cycle
3. Execute (Carry out instructions) The opcode is sent to and executed by the ALU.
12 Software Design and Development
Fetch-Execute Cycle
4. Store(Copy the result) Results during processing are stored in the
accumulator. Once processing is complete results are then sent
to main memory.
12 Software Design and Development
Processing Instructions
Sum = Total + Number
Source Code
// Assume Sum is at address 101// Assume Total is at address 134// Assume Number is at address 135
0. LOAD A 1341. LOAD B 1352. DIV4. SAVE C 1015. STOP
Assembly Code
Machine Code
10110 10001111 111010000110
10110 11101111 101010000110
10000 10101111 100010000110
11110 10000011 100111100110
10100 11101111 100000000000
00110 11001111 100010001110
12 Software Design and Development
Translation
Why does it occur? Computers cannot understand machine code.
Source Code
Machine Code
Translator
12 Software Design and Development
Translation Process
1. Interpreter Source code is translated line by line and
immediately executed. If errors exist they will cause an immediate halt.
German sentence is spoken. INTERPRETER
GERMAN ENGLISH
English sentence is spoken.
Interpreter translates message from German to English.
12 Software Design and Development
Translation Process
2. Compilation Known as ‘Batch Processing’ as an entire
executable file is created. All errors are recorded and sent at the end. If changes are required then recompilation will be
required.
TRANSLATOR ENGLISH
The translator converts the German in a novel for English
12 Software Design and Development
Translation Process
3. Incremental Compilation The aim is to reduce the time spent recompiling. Incremental compilers aim to reduce the
translation time by only recompiling those parts of code that have changed since the last compile took place.
TRANSLATOR
The translator converts the new changes into a new edition.
1st Edition
Changes
2nd Edition
12 Software Design and Development
Translation Process in Detail
LexicalAnalysis
SyntacticalAnalysis
CodeGeneration
Object Code
Error File
Source CodeHigh Level Code
Error
Series of Tokens
Error
SyntacticallyCorrect Tokens
Machine Code
12 Software Design and Development
Lexical Analysis
Requires the source code to be read one character at a time.
Each character is scanned and redundant characters such as remarks, spaces and indentation are removed.
Variables, constants, operators, strings of text and control structures are labelled with a token.
Most translators have a token dictionary.
12 Software Design and Development
Lexical AnalysisToken Type
& VARIABLE
@ BEGIN
# END
$ IF
? THEN
{} ELSE
[] ENDIF
<> OPERATOR
:: GET
% CONSTANT
!! STRING
Given the Following Source Code:
BEGIN
Get Number
IF Number > 10 THEN
Print OK
ELSE
Print No
ENDIF
END
What would be the tokens?
12 Software Design and Development
Lexical Analysis
ANSWER
@
:: &
$ & <>% ?
() !!
{}
() !!
[]
#
12 Software Design and Development
Syntactical Analysis
The tokens are then passed through the syntactic analyser to determine the logic of the code.
The syntactic analysis involves an examination of whether the identified elements in the statements are legal according to the syntax of the language.
This process is best understood by a Parse Tree.
12 Software Design and Development
Syntactical Analysis
Parse Tree
Selection
IF Condition Then Statement
Variable Operator Constant
Else Statement
String String
12 Software Design and Development
Syntactical Analysis
Parse Tree
Selection
IF Condition Then Statement
Variable Operator Constant
Else Statement
String String
Number
&
>
<>
10
%
Print OK
() !!
Print No
()!!
12 Software Design and Development
Production of Machine Code
This undertaken when the processes of lexical and syntactical analysis have been completed an no errors found.
This stage involves converting each token into their respective machine code instructions.
All characters in strings are converted to binary code using their ASCII values.
Tokens are collected left to tight from the parse tree in a method called transversing.
12 Software Design and Development
Production of Machine Code
This undertaken when the processes of lexical and syntactical analysis have been completed an no errors found.
This stage involves converting each token into their respective machine code instructions.
All characters in strings are converted to binary code using their ASCII values.
Tokens are collected left to tight from the parse tree in a method called transversing.
12 Software Design and Development
Translation Tools1. LINKER Does what the name suggests it links the main line
to all the other sub modules.
2. LOADER This is the component of the translator that loads
the module from main memory.
3. OPTIMISER Used to reduce redundant code for quick execution