lesson 5. gcse computing – programming languages candidates should be able to: explain the...

13
Lesson 5 GCSE Computing

Upload: nyah-dalton

Post on 29-Mar-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Lesson 5

GCSE Computing

Page 2: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

GCSE Computing – programming languages

Candidates should be able to:

explain the difference between high level code and machine code

explain the need for translators to convert high level code to machine code

describe the characteristics of an assembler, a compiler and an interpreter

Slide 2

Page 3: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

What is machine code?

Machine code instructions are the binary code instructions that the CPU actually executes when an executable program runs.

Each machine code instruction performs a very specific task:

either an operation on some data (addition/subtraction, input/output); or an operation to decide which instruction executes next (branching or

conditional branching based on the results of a previous instruction).

Machine code can be regarded as an extremely hardware-dependent programming language because the instructions are often specific to a particular series of CPU designs.

Slide 3

Page 4: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Because each instruction is a binary number it is very difficult for humans to read or develop software directly using machine code.

Assembly language was developed to solve this problem (followed by increasingly advanced high level programming languages).

Slide 4

Can a program be written directlyIn machine code?

01001010010001101110101010010100110100010101010101001000101101001010100101010010101010000010000100111010001000010010000100101010101000110111001100101010011010010010010100101001

Page 5: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Assembly language is a very simple programming language that uses mnemonics (memory aids) to directly represent machine code instructions.

There is therefore nearly between assembly language instructions and machine code instructions.

An assembler TRANSLATES assembly language instructions into machine code instructions.

Because of the one-to-one match, a machine code program translated from assembly language is very efficient (it will require less memory and run faster than a machine code program translated from a high level language using a compiler).

Slide 5

What is assembly language and an assembler?

Page 6: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Advantages of writing programs in assembly language: It usually creates fast running programs because the one-to-one match

means that the machine code program created will tend to be very efficient. The translation into machine code will be very fast due to the one-to-one

match between assembly language instructions and machine code instructions. Relatively easy to understand compared to machine code due to the use of

mnemonics and labels.

Disadvantages of writing programs in assembly language: Different versions of an assembly language are often required for different

processors making it difficult to transfer programs between processors. Assembly language programs are often written for specific hardware which

means they are often incompatible with different hardware. A lot of assembly code is needed to do relatively simple tasks so complex

programs require a lot of assembly instructions and it will take a lot time to write the program.

Slide 6

Comparing machine code and assembly language

Page 7: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

The mnemonic instructions are just 2 or 3 letter codes that are far easier to remember than number codes.(for example: LDA = LOAD, STA = STORE)

Labels are used to: Label the memory addresses of data so the data can be referred to by name; Label the memory addresses of instructions so the program can branch to an

instruction at a named memory location.

The simple assembly language program below inputs a number, then in a loop it outputs the count down from that number until it reaches zero.

Slide 7

INPLOOP SUB ONE // RAM address label LOOP. Subtract value stored at RAM address ONE OUT // Output the number BRZ QUIT // If at 0, branch to RAM address QUIT BRA LOOP // Not at 0 so branch to RAM address LOOPQUIT HLT // RAM address label QUIT. End the program ONE DAT 1 // DATA, store 1 in this RAM address, and label it ONE

How are mnemonics used?

Page 8: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

High-level code (source code) is made up of statements written in high-level languages such as Visual Basic, C++, Delphi and Java.

Such languages allow a programmer to write instructions that can be understood far more easily than machine code.

High level source code will make use of some or all of the following: Keywords - reserved words such as SORT, IF, FUNCTION etc.

which are simple to understand and would involve a lot of programming using machine code.

Syntax - rules for the use of keywords and the arguments that go with them.

More complex iteration and conditional programming structures than just simple branches

What is high level code?

Slide 8

Java C++

Page 9: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Why are translators needed?

The CPU can only execute machine code instructions.This means that every executable program, no matter what

the language it is written in, has to be translated into machine code.

This is carried out by two types of program:a compileran interpreter

Slide 9

Page 10: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Comparing a compiler and an interpreter

A compiler A compiler is used once the source code has been fully developed and tested. It translates all the source code into machine code and creates a new file which

can be executed by the CPU as a stand-alone program. This translation can involve several stages and may take a considerable amount of

time because one source code instruction may translate into hundreds of machine code instructions.

Advantages of using a compiler: The source code is not included so compiled code is more secure than

interpreted code. It produces an executable file so the program can be run without the source

code. Disadvantages of using a compiler:

It is a slow process translating the source code into machine code.

Slide 10

Page 11: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Comparing a compiler and an interpreterAn interpreter. An interpreter allows the programmer to run the source code but only within the

interpreter. It does this by translating the source code into the equivalent machine code line-

by-line as the program is running. Advantages of using an interpreter:

It is easier to check for errors than with a compiler because the error can easily be traced to the line of source code that generated it.

It is faster to develop software because the whole program does not need to be compiled every time something needs to be tested.

Disadvantages of using an interpreter: The program cannot be executed without the source code. Because the source code needs to be available and is usually just text, the

program to be executed is less secure. An interpreted program will execute more slowly than a compiled program due to

the line-by-line translation.

Slide 11

Page 12: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Summary

Machine code instructions are the binary code instructions that the CPU actually executes.

Assembly language uses easily remembered codes to directly represent machine code instructions.

All executable programs have to be translated into machine code before the CPU can run them.

An assembler translates assembly language programs into machine code.

A compiler translates all the source code into machine code and creates a stand-alone program which the CPU executes.

An interpreter allows the programmer to run the source code within the interpreter by translating the source code into the equivalent machine code as the program is running.

Slide 12

Page 13: Lesson 5. GCSE Computing – programming languages Candidates should be able to: explain the difference between high level code and machine code explain

Task

Using the LMC and the worksheet 1 enter in the programs and execute them to see how the computer deals with the program

Try and have a go of the questions in worksheet 2