Presentation is loading. Please wait.

Presentation is loading. Please wait.

High and low level languages

Similar presentations


Presentation on theme: "High and low level languages"— Presentation transcript:

1 High and low level languages
CfE Computing Science Higher

2 Learning intentions To understand the differences between low-level languages and high-level languages. To know the differences between interpreter and compiler translator programs. Success criteria I can describe how the computer stores data and instructions in binary. I can state that, in order for it to run, a program written in a high-level language must be translated into binary. I can describe the advantages/disadvantages of both an interpreter and compiler program.

3 Low-level languages Processors can only understand machine code (binary). Ultimately, everything that is processed by a computer is handled in one of two states, 1 or 0. REMINDER - The number 1 represents on and the number 0 represents off. Can you imagine attempting to write a program in binary? This would be time- consuming and one tiny error could result in the wrong instruction being sent to the processor. We use high-level languages such as Python, scratch and Visual Basic to program. Two common low-level languages are assembly code and machine code.

4 Machine and hexadecimal code
Machine code is the term used to describe binary instructions, e.g Machine code can be represented by Hexadecimal code. Programming in hexadecimal saves time when compared to using binary instructions. Instruction in machine code Same instruction in hexadecimal B4 00 B0 13 CD 10

5 Hexadecimal code Decimal Binary Hexadecimal 00000000 00 1 00000001 01
00 1 01 2 02 3 03 10 0A 15 0F 16 17 11 25 19 26 1A

6 Assembly code Assembly code is created by the developers of processors. Assembly languages are architecture dependent - the form of assembly code depends upon the manufacturer of the processor. An assembler is the name given to the software that converts assembly code into binary instructions. The main drawbacks of assembly languages are lack of portability and the time that it takes to learn how to program.

7 Low-level language summary
Low-level languages generally allow for a one to one conversion into machine code (binary) Hexadecimal and assembly code are examples of low-level languages Assembly code is architecture dependent (different codes exist for different types of processor) Assembly code is not fully portable because of architecture dependence. Assembly code needs to be converted to binary using an assembler. Low-level languages are difficult to learn. Reasons for using low-level languages include optimisation of code, lack of translator software, allows greater control of hardware features.

8 High-level languages Most programmers will use a high-level programming languages. They have the following characteristics: Require translation into machine code Portable (can be used on different computer systems) Easier to read, write and maintain as commands are similar to English Allow access to module libraries (more on these later) Use data types and data structures, selection statements and repetition/iteration constructs Use logic operators and functions that are built into the language

9 High-level languages High-level languages require translator software that will be held in RAM when a program is executed. This piece of software is responsible for taking the code written in a high-level language and translating it into 'executable code'. (in binary form and therefor can be understood by the processor). For I in range (4): name = input(“Please enter your name”) print(name) Translator Translator software usually comes in the form of either a compiler or an interpreter.

10 Interpreter An interpreter works by translating and executing one line of the source code at a time. Advantages Execution will stop if the interpreter encounters an error. This makes debugging much easier as the programmer can then pinpoint which line of code has caused the error. Disadvantages An interpreter has to be present in main memory while the source code is being executed. This means it is less efficient than a compiler.

11 Compiler A compiler will translate the source code into object code.
Advantages The compiler is held in RAM only for the time that it takes to translate the source code into object code. This makes it more efficient than an interpreter. Once object code has been created it is possible to run this code independently of the development environment and translator software. This makes the program more portable. Disadvantages If the source code contains errors the programmer would need to re-compile to make use of the corrected object code. The compiler would also be unable to pinpoint which line of code caused the error.

12 Translator software As high-level languages depend upon translator software to convert instructions into binary, they do not depend on a specific hardware architecture. Software that can be used in this way is called portable software. Programmers can also access module libraries when they are using a high-level language. Module libraries contain sections of pre-written and pre-tested code that can be used without the need to spend additional time on creation and testing.

13 Types of high-level language
There are three forms of high-level language within the Higher Computing Science course: Procedural language Declarative language Object orientated language

14 Procedural languages Procedural languages are designed to allow programmers to create code that will be processed logically and in a structured order. Code is contained within procedures (also called subroutines). Procedures will be created to allow a series of steps to be followed. Data can be passed from procedure to procedure using parameters. The concept of passing data from procedure to procedure is called parameter passing (more on this later). Get_info (IN: OUT: name, hours_worked, pay) RECEIVE name FROM KEYBOARD RECEIVE hours_worked FROM KEYBOARD RECEIVE pay FROM KEYBOARD RETURN name, hours_worked, pay Procedure 1 Calculate_pay (IN: hours_worked, pay OUT: total pay) SET total_pay TO hours_worked * pay RETURN total_pay Procedure 2

15 Declarative languages
Declarative languages are often used by intelligent systems. Declarative languages are very different to the other types of language because of the way that the language is structured. Programmers will create a knowledge base. A knowledge base contains a series of related facts and rules. For example: dislikes(miss_alexander, one_direction) – Miss Alexander dislikes One Direction likes(miss_alexander, football) – Miss Alexander likes football has(miss_alexander, pet_snakes) – Miss Alexander has pet snakes

16 Declarative languages
We can set up a set of facts like so: likes(ryan,stacey) – Ryan likes Stacey likes(stacey,ryan) – Stacey likes Ryan likes(danny,lianne) – Danny likes Lianne We wish to set up a rule that determines whether two people should go on a date. This should only be recommended if both people like each other. dating (X, Y) :- likes (X, Y ), likes (Y, X).

17 Declarative languages
To query this knowledge base we could enter the following query which would give the answer “true”: ?- likes(ryan,stacey) True To query this knowledge base on the dating rule we could enter the following queries which would give the answers “true” and false: ?- dating(ryan,stacey) true ?- dating(danny,lianne) false

18 Declarative languages
operator meaning :- IF , AND ; OR NOT

19 Object orientated programming
Object-oriented programs are designed around objects rather than sequences of instructions Each type of item used in a OO program is described using code called a class A class has a list of attributes and a list of methods Each class can be used as the blueprint to create an object, for example the code in a class called Square could describe the attributes and methods of a square, and each square the program uses would be created as an object Objects are closed off from other areas of the program – the design of the object determines which attributes and methods can be called from other parts of the program. This is called encapsulation. Each class can be used as the base code for another class, and the programmer can add on new attributes and methods. For example, the Shape class could have two subclasses called Square and Triangle. Creating a subclass from an existing class is called inheritance One of the major advantages of using classes is that each class can be used to create many objects of the same design. Not only this, but the design can be built on using a subclass. A subclass takes all the attributes and methods of a class and adds to them.

20 Task Create your own summary notes covering types of high-level languages (be sure to research examples of each type).


Download ppt "High and low level languages"

Similar presentations


Ads by Google