1 / 13

GCSE Computing

GCSE Computing . Lesson 5. 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.

lori
Download Presentation

GCSE Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GCSE Computing Lesson 5

  2. 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 GCSE Computing – programming languages

  3. 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. What is machine code?

  4. Can a program be written directly In machine code? • 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). 0100101001000110 1110101010010100110100010101010101001000101101001010100101010010101010000010000100111010001000010010000100101010101000110111001100101010011010010010010100101001

  5. Whatis assembly language and an assembler? • 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 assemblerTRANSLATES 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).

  6. Comparing machine code and assembly language • 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.

  7. How are mnemonics used? • 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. INP LOOP 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 LOOP QUIT HLT // RAM address label QUIT. End the program ONE DAT 1 // DATA, store 1 in this RAM address, and label it ONE

  8. 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? Java C++

  9. 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 compiler • an interpreter Why are translators needed?

  10. 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. Comparing a compiler and an interpreter

  11. An 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. Comparing a compiler and an interpreter

  12. 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. Summary

  13. TaskUsing the LMC and the worksheet 1 enter in the programs and execute them to see how the computer deals with the programTry and have a go of the questions in worksheet 2

More Related