Unit 2 Computational Thinking Algorithms Programming Translators Facilities

  • Slides: 18
Download presentation
Unit 2: Computational Thinking, Algorithms & Programming Translators & Facilities of Languages 2. 5

Unit 2: Computational Thinking, Algorithms & Programming Translators & Facilities of Languages 2. 5

Unit 2: Computational Thinking, Algorithms & Programming 27 November 2020 Translators & Facilities of

Unit 2: Computational Thinking, Algorithms & Programming 27 November 2020 Translators & Facilities of Languages Learning Objective: To be able to demonstrate an understanding of translators, levels of programming languages and IDE. Success Criteria: 1. I can describe the characteristics and purpose of high and low level programming languages. 2. I can explain the purpose of translators. 3. I can describe the characteristics of an assembler, a compiler and an interpreter. 4. I can discuss the common tools in an IDE.

Unit 2: Computational Thinking, Algorithms & Programming Languages There are several Generations of Programming

Unit 2: Computational Thinking, Algorithms & Programming Languages There are several Generations of Programming Languages: – Low Level ◦ 1 st Generation ◦ 2 nd Generation – High Level ◦ 3 rd Generation ◦ 4 th Generation

Unit 2: Computational Thinking, Algorithms & Programming 1 st Generation • Machine Code •

Unit 2: Computational Thinking, Algorithms & Programming 1 st Generation • Machine Code • Directly Executable by the processor • The Generation that “computers understand” • Difficult to program in, hard to understand, hard to find errors (hard to debug)

Unit 2: Computational Thinking, Algorithms & Programming 2 nd Generation • Assembly Code •

Unit 2: Computational Thinking, Algorithms & Programming 2 nd Generation • Assembly Code • Uses mnemonics • Easier to program in than 2 nd Generation but still difficult. • One Assembly Language instruction translates to one Machine Code Instruction (1 -1 relationship) • Needs to be translated into Machine Code for the computer to be able to execute it • Uses an Assembler • Assembler – Assembles Assembly Language

Unit 2: Computational Thinking, Algorithms & Programming 2 nd Generation • Despite 2 nd

Unit 2: Computational Thinking, Algorithms & Programming 2 nd Generation • Despite 2 nd Generation being difficult to Debug it still has its uses – Debug means to go through the code to search for where/why an error has occurred • It is most commonly used to program Device Drivers – Device Drivers are loaded into memory by the Operating System and used to control the operation of a Hardware Device e. g. Graphics Card Drivers, Printer Drivers.

Unit 2: Computational Thinking, Algorithms & Programming rd 3 Generation Easier to understand (programmer)

Unit 2: Computational Thinking, Algorithms & Programming rd 3 Generation Easier to understand (programmer) Easier to find errors, easier to de-bug Uses English-Like Keywords One instruction translates into many machine code instructions • For example: Java, Basic, Pascal, C+ • Translated using: • • – Compiler – Interpreter

Unit 2: Computational Thinking, Algorithms & Programming 4 th Generation • Known as a

Unit 2: Computational Thinking, Algorithms & Programming 4 th Generation • Known as a Declarative Language • Facts and Rules are stated • Describes what computation should be performed and not how to perform it • Examples include: – SQL – Expert Systems – Artificial Intelligence

Activity 3 – Identify the Generation Dim Num 1, Num 2, Tot as Integer

Activity 3 – Identify the Generation Dim Num 1, Num 2, Tot as Integer Num 1 = Console. Readline() Num 2 = Console. Readline() Tot = Num 1 + Num 2 Console. Writelein(“Total is: “ & Tot) High Level (3 rd Generation) 010101001010010100111110010000 1010100101 Low Level (2 nd Generation) LOAD r 1, c LOAD r 2, d ADD r 1, r 2 DIV r 1, #2 Low Level (1 st Generation – Machine Code)

Unit 2: Computational Thinking, Algorithms & Programming Exam Question Q 11 a Answers: (marks

Unit 2: Computational Thinking, Algorithms & Programming Exam Question Q 11 a Answers: (marks in pairs) • In high level code Instructions use words • In machine code instructions are in binary code • High-level code is designed to be read by human programmers • Machine code is to be read/executed by the computer • High level code can be portable/translated for different machines • Machine code is specific to a particular machine

Unit 2: Computational Thinking, Algorithms & Programming Content • Language Translators are used to

Unit 2: Computational Thinking, Algorithms & Programming Content • Language Translators are used to translate a language into a form that the will be able to directly execute – Assemblers are used for 2 nd Generation – Compilers/Interpreters are used for 3 rd Generation

Unit 2: Computational Thinking, Algorithms & Programming What is a Translator? • A translator

Unit 2: Computational Thinking, Algorithms & Programming What is a Translator? • A translator is a piece of software that converts programming code into machine code. • The programming code could be high level source code or low level assembly instructions. • The machine code then runs in the CPU hardware - or it is stored as a file and later loaded in the CPU to run.

Unit 2: Computational Thinking, Algorithms & Programming What are the different types of translators?

Unit 2: Computational Thinking, Algorithms & Programming What are the different types of translators? There are three different types of translators which are: • Assembler - converts assembly language instruction into machine code • Compiler - converts high level source code into machine code and stores it in an executable file • Interpreter - converts a single line of high level source code into machine code and then immediately runs it on the CPU.

Unit 2: Computational Thinking, Algorithms & Programming Compilers • A compiler is a language

Unit 2: Computational Thinking, Algorithms & Programming Compilers • A compiler is a language translator that transforms source code written in a programming language into machine code (also known as object code). A compiler produces this executable program (Object code) • Machine code consists of 0’s and 1’s and is directly understandable by the CPU. Therefore High Level code must be translated into Low Level code so that the computer can understand execute it. • A compiler will go through the entire source code in one go, translating the entire source code at once. It will optimise the code as it does so. • If a compiler encounters errors, it produces an error report that it outputs along with the object code.

Unit 2: Computational Thinking, Algorithms & Programming Compilers • Compiled code tends to execute

Unit 2: Computational Thinking, Algorithms & Programming Compilers • Compiled code tends to execute much quicker than interpreted code • Compilers tend to be used once a program development is finished so that the program can then be shipped out to customers and no compiler is needed during run-time. Customers therefore will not have access to the source code.

Unit 2: Computational Thinking, Algorithms & Programming Interpreter • • An interpreter analyses and

Unit 2: Computational Thinking, Algorithms & Programming Interpreter • • An interpreter analyses and executes each line of a high-level language program without looking at the entire program. Execution will be slower than for the equivalent compiled code as the source code is analysed statement by statement (line by line) during execution. As each statement is analysed the interpreter calls routines to carry out each instruction. No object code is generated. This means the program has to be interpreted each time it is run. The advantages of interpreters over compilers are that a program can be executed immediately without having to wait for it to be compiled. If a compiler and an interpreter exist for a high-level language, a programmer may use the interpreter to test sections during development When an interpreter is working – if it encounters an error it will stop the interpreting and flag up the error to the programmer.

Unit 2: Computational Thinking, Algorithms & Programming Assemblers • Assemblers convert assembly code into

Unit 2: Computational Thinking, Algorithms & Programming Assemblers • Assemblers convert assembly code into machine code (Binary form). • Every CPU has an instruction set made up of assembly language mnemonics. • And every CPU comes with a program called an assembler that translates mnemonics directly into machine code that the CPU can read. • Different CPU families will require different assemblers.

Unit 2: Computational Thinking, Algorithms & Programming Exam Question Practise A company specialises in

Unit 2: Computational Thinking, Algorithms & Programming Exam Question Practise A company specialises in writing programs using low-level languages. a) Identify two reasons why some programmers still use low-level languages. 1. __________________________ 2. __________________________ [2] b) Explain why programmers might prefer to use an assembly language over machine code. ___________________________________________________ [2] c) State the type of translator used to translate assembly languages into machine code. __________________________ [1]