Implementation  TRANSLATION
Syllabus Different Methods include: Translation Incremental Compilation Interpretation Advantages and disadvantages of each method The translation process.
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.
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.
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.
Hierarchy of Code Translation Source Code Assembly Code Machine Code Opcode Operand Operand Instruction Address Data
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 100010101 100100111111
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 .
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.
Fetch-Execute Cycle 3. Execute (Carry out instructions) The opcode is sent to and executed by the ALU.
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.
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 134 LOAD B 135 DIV SAVE C 101 5. STOP Assembly Code Machine Code 10110 10001111  111010000110 10110 11101111  101010000110 10000 10101111  100010000110 11110 10000011  100111100110 10100 11101111  100000000000 00110 11001111  100010001110
Translation Why does it occur? Computers cannot understand machine code. Source Code Machine Code Translator
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.
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
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. 1 st  Edition Changes 2 nd  Edition
Translation Process in Detail
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.
Lexical Analysis Given the Following Source Code: BEGIN Get Number IF Number > 10 THEN Print OK ELSE Print No ENDIF END What would be the tokens? STRING !! CONSTANT % PRINT () GET :: OPERATOR <> ENDIF [] ELSE {} THEN ? IF $ END # BEGIN @ VARIABLE & Type Token
Lexical Analysis ANSWER @ :: & $ & <>% ? () !! {} () !! [] #
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.
Syntactical Analysis Parse Tree Selection IF Condition Then Statement Variable Operator Constant Else Statement String String
Syntactical Analysis Parse Tree Selection IF Condition Then Statement Variable Operator Constant Else Statement String String Number & > <> 10 % Print OK () !! Print No ()!!
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.
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.
Translation Tools 1. 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

SDD Translation

  • 1.
  • 2.
    Syllabus Different Methodsinclude: Translation Incremental Compilation Interpretation Advantages and disadvantages of each method The translation process.
  • 3.
    Why Study theCPU? 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.
  • 4.
    Why Study theCPU? 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.
  • 5.
    Why Study theCPU? 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.
  • 6.
    Hierarchy of CodeTranslation Source Code Assembly Code Machine Code Opcode Operand Operand Instruction Address Data
  • 7.
    What is MachineCode? 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 100010101 100100111111
  • 8.
    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 .
  • 9.
    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.
  • 10.
    Fetch-Execute Cycle 3.Execute (Carry out instructions) The opcode is sent to and executed by the ALU.
  • 11.
    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.
    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 134 LOAD B 135 DIV SAVE C 101 5. STOP Assembly Code Machine Code 10110 10001111 111010000110 10110 11101111 101010000110 10000 10101111 100010000110 11110 10000011 100111100110 10100 11101111 100000000000 00110 11001111 100010001110
  • 13.
    Translation Why doesit occur? Computers cannot understand machine code. Source Code Machine Code Translator
  • 14.
    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.
  • 15.
    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
  • 16.
    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. 1 st Edition Changes 2 nd Edition
  • 17.
  • 18.
    Lexical Analysis Requiresthe 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.
  • 19.
    Lexical Analysis Giventhe Following Source Code: BEGIN Get Number IF Number > 10 THEN Print OK ELSE Print No ENDIF END What would be the tokens? STRING !! CONSTANT % PRINT () GET :: OPERATOR <> ENDIF [] ELSE {} THEN ? IF $ END # BEGIN @ VARIABLE & Type Token
  • 20.
    Lexical Analysis ANSWER@ :: & $ & <>% ? () !! {} () !! [] #
  • 21.
    Syntactical Analysis Thetokens 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.
  • 22.
    Syntactical Analysis ParseTree Selection IF Condition Then Statement Variable Operator Constant Else Statement String String
  • 23.
    Syntactical Analysis ParseTree Selection IF Condition Then Statement Variable Operator Constant Else Statement String String Number & > <> 10 % Print OK () !! Print No ()!!
  • 24.
    Production of MachineCode 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.
  • 25.
    Production of MachineCode 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.
  • 26.
    Translation Tools 1.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