Programming Languages & Translators Flashcards
All 19 cards in this deck
What is a high-level programming language?
A programming language written in a form close to human language, which must be translated into machine code by a compiler or interpreter before it can run.
What is a low-level programming language?
Machine code or assembly language — written for one specific type of processor and giving direct control of the hardware and memory.
Give two reasons why some programs are written in a low-level language.
Any two of: the program runs faster / uses less processor time; it uses less memory; it can directly control the hardware, e.g. in an embedded system; no unnecessary code is added by a compiler.
Give two reasons why a programmer would choose a high-level language.
It is easier to write, understand and debug, as it uses English-like keywords; it is portable, so the same source code can be translated to run on different types of processor.
True or false? Machine code must be translated before a computer can run it.
False. Machine code does not need to be translated / compiled / interpreted — the processor executes it directly.
What is the purpose of a translator?
To translate program code written in a high-level language or assembly language so it can be executed. Processors can only execute machine code, so all other code must be translated.
Describe the characteristics of a compiler.
It translates the whole program in one go into machine code, producing an executable file, and reports the errors it finds after translation. The executable then runs without the compiler or the source code.
Describe the characteristics of an interpreter.
It translates and executes the program one line at a time and stops when it finds an error. It produces no executable file or machine code: it calls machine-code subroutines within its own code to carry out each statement.
Give two benefits of using a compiler instead of an interpreter.
It produces an executable file, so end users do not need a translator; the program runs faster than the interpreted version.
Also: it only needs translating once, and the compiler can optimise the code.A programmer is still writing and testing a program, changing it after every run. Should they use a compiler or an interpreter, and why?
An interpreter — it runs the code straight away without re-translating the whole program, and stops at the error so its location is easy to find.
Give two disadvantages of writing a program in a low-level language.
Any two of: the code is difficult to read, write and debug; it is not portable, as it normally runs on only one type of processor; it takes longer to write.
Give two disadvantages of a high-level language compared with a low-level language.
Any two of: it must be translated before it can run; the program usually runs more slowly; it tends to use memory less efficiently; it gives less direct control of the hardware.
How many machine code instructions does one assembly language instruction correspond to, compared with one high-level statement?
One assembly language instruction corresponds to exactly one machine code instruction (a 1:1 correspondence). One high-level statement usually stands for many machine code instructions.
Give two drawbacks of using a compiler.
Any two of: translating the whole program can take a long time; errors are only reported, all together, after compilation finishes, which can make them harder to track down; the program must be recompiled after every change.
Give two drawbacks of using an interpreter.
Any two of: the program runs more slowly, because each line is translated every time it runs; the interpreter must be present every time the program is run; the source code has to be given to users, so it can be seen and copied.
What is machine code?
Instructions written in binary that the processor executes directly. Each type of processor has its own instruction set, so machine code is specific to a processor or family of processors.
What is assembly language?
A low-level language that uses short text mnemonics (e.g. ADD, LDR) in place of binary machine code instructions. It is often used for embedded systems and for controlling specific hardware.
How can you tell machine code, assembly language and high-level code apart?
Machine code is binary (0s and 1s); assembly language uses mnemonics such as ADD with operands; high-level code uses English-like statements such as IF and WHILE.
What does an assembler do?
It translates a program written in assembly language into machine code, so that the processor can execute it.