26
12 Software Design and Developme nt Implementation TRANSLATION

SDD Translation

  • Upload
    gavhays

  • View
    1.969

  • Download
    2

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: SDD  Translation

12 Software Design and Development

Implementation

TRANSLATION

Page 2: SDD  Translation

12 Software Design and Development

Syllabus

Different Methods include: Translation Incremental Compilation Interpretation

Advantages and disadvantages of each method

The translation process.

Page 3: SDD  Translation

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.

Page 4: SDD  Translation

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.

Page 5: SDD  Translation

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.

Page 6: SDD  Translation

12 Software Design and Development

Hierarchy of Code Translation

Source Code

Assembly Code

Machine Code

Opcode Operand Operand

Instruction Address Data

Page 7: SDD  Translation

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

Page 8: SDD  Translation

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.

Page 9: SDD  Translation

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.

Page 10: SDD  Translation

12 Software Design and Development

Fetch-Execute Cycle

3. Execute (Carry out instructions) The opcode is sent to and executed by the ALU.

Page 11: SDD  Translation

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.

Page 12: SDD  Translation

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

Page 13: SDD  Translation

12 Software Design and Development

Translation

Why does it occur? Computers cannot understand machine code.

Source Code

Machine Code

Translator

Page 14: SDD  Translation

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.

Page 15: SDD  Translation

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

Page 16: SDD  Translation

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

Page 17: SDD  Translation

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

Page 18: SDD  Translation

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.

Page 19: SDD  Translation

12 Software Design and Development

Lexical AnalysisToken Type

& VARIABLE

@ BEGIN

# END

$ IF

? THEN

{} ELSE

[] ENDIF

<> OPERATOR

:: GET

() PRINT

% 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?

Page 20: SDD  Translation

12 Software Design and Development

Lexical Analysis

ANSWER

@

:: &

$ & <>% ?

() !!

{}

() !!

[]

#

Page 21: SDD  Translation

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.

Page 22: SDD  Translation

12 Software Design and Development

Syntactical Analysis

Parse Tree

Selection

IF Condition Then Statement

Variable Operator Constant

Else Statement

String String

Page 23: SDD  Translation

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

()!!

Page 24: SDD  Translation

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.

Page 25: SDD  Translation

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.

Page 26: SDD  Translation

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