SDD Translation

1,702 views

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,702
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
35
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

SDD Translation

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

×