3.4.4 Classification of programming languages and translators Flashcards

1
Q

What are the instructions that tell a computer what to do written in?
What actually is this?
What does each ‘thing’ represent?

A

The instructions that tell a computer what to do are written in machine code.
Machine code is a series of numbers written in binary.
Each number represents a different instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • How do programmers find machine code (to do 3 things)
  • so what do they do
  • and this way is good cos

Big chunk

A

Programmers find machine code difficult to learn, program in and debug.
As a result, the majority of programmers write programs in high-level programming languages.
These languages are close to natural language - the spoken and written language of humans.
For example, Python uses ‘print’, ‘if’, ‘input’ and ‘while’ statements - all words from the English language - to form instructions.
In fact, instructions often look like abbreviated English sentences.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do programmers write in high level languages? (2)
+ what do they allow
+ example

A

Programmers write in high-level languages because they are easier to understand and are less complex than machine code.
They allow the programmer to focus on what needs to be done, rather than on how the computer actually works.

For example, in many high-level languages, to place a message on the screen, a programmer would use the statement ‘print’. The programmer might not know how the computer actually generates the message. They just need to know how to use the ‘print’ statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Many types of high-level language exist and are in common use today, including:
(6)

A
  • Python
  • Java
  • C++
  • C#
  • Visual Basic
  • JavaScript
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s source code

A

Source code is the term given to a set of instructions that are written in human readable programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What must happen to source code ?

A

Source code must be translated into machine code before a computer can understand and execute it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Low level languages are what?

A

Low-level languages are languages that sit close to the computer’s instruction set. An instruction set is the set of instructions that the processor understands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Two types of low-level language are:

A

Two types of low-level language are:

machine code
assembly language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

So what’s machine code

A

Machine code is the set of instructions that a CPU understands directly and can act upon. A program written in machine code would consist of only 0s and 1s - binary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Machine code disadvantages (2 kinda) + why

A

This is very difficult to write and debug. Even a very simple program could have thousands of 0s and 1s in it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s assembly language

A

Assembly language sits between machine code and high-level language in terms of ease of use. While high-level languages use statements to form instructions, assembly language uses mnemonics - short abbreviations. Each mnemonic directly corresponds with a machine code instruction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Assembly language.

Here are some examples of mnemonics:

A

Mnemonic Action
LDA Loads a value from a memory address
STA Stores a value in a memory address
ADD Adds the value held in a memory address to the value held in the accumulator
SUB Subtracts from the accumulator the value held in a memory address
MOV Moves the contents of one memory address to another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Adv of assembly languages

A

In assembly language, programmers write programs as a series of mnemonics. Mnemonics are much easier to understand and debug than machine code, giving programmers a simpler way of directly controlling a computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why are mnemonics easier for programmers

A

Writing in mnemonics is easy for programmers because they are usually brief representations of the actual commands. They are quicker to write than binary, and it is easier to spot mistakes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Many machine code and assembly instructions contain two parts

A

Many machine code and assembly instructions contain two parts:

the opcode - this is the actual instruction

the operand - this is a value that the instruction uses or manipulates

Consider this set of program instructions:

Assembly language Opcode Operand Instruction
INP 1001 00000000 Input a number
STR 6 0011 00000110 Store it in address 06
LDR A1 0101 10100001 Load data from address A1
ADD #10 0010 00001010 Add the number 10 to the loaded address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Both opcode and operand values are ultimately represented in ?

However, ?

A

Both opcode and operand values are ultimately represented in binary. However, values may also be represented in hexadecimal when programming as this number system can represent larger values in fewer characters, for example, denary 250 is 11111010 in binary, but only FA in hexadecimal. Hexadecimal is therefore easier to read and understand by humans.

17
Q

Any program written in high-level langauge is known as

A

Source code

18
Q

Why must source code be translated

A

computers cannot understand source code. Before it can be run, source code must first be translated into a form which a computer understands.

19
Q

What is a translator ?

What are the three types? - just names

A

A translator is a program that converts source code into machine code.

Generally, there are three types of translator:

compilers
interpreters
assemblers

20
Q

SPEC:
What executes machine code ?
What do each type of these have?

A
  • processors execute machine code

- each type of processor has its own specific machine code instruction set

21
Q

SPEC:

What’s assembly language often used for (2)

A
  • to develop software for embedded systems

- and for controlling specific hardware components

22
Q

SPEC:

Correspondence of assembly language with machine code

A

1:1

23
Q

Tell me about a compiler

  • what to does
  • and then
  • process called?
A

A compiler takes the source code as a whole and translates it into machine code all in one go. Once converted, the object code can be run unassisted at any time. This process is called compilation.

24
Q

3 adv compilers

A
  • Compiled programs run quickly, since they have already been translated.
  • A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.
  • Compilers optimise code. Optimised code can run quicker and take up less memory space.
25
Q

Compilers disadvantages (2)

A
  • The source code must be re-compiled every time the programmer changes the program.
  • Source code compiled on one platform will not run on another - the machine code is specific to the processor’s architecture.
26
Q

Tell me about interpreters

  • what does
  • similar to
  • result
  • process called
A

An interpreter translates source code into machine code one instruction at a time. It is similar to a human translator translating what a person says into another language, sentence by sentence, as they speak. The resulting machine code is then executed immediately. The process is called interpretation.

27
Q

Interpreters have several advantages: (2)

A
  • Instructions are executed as soon as they are translated.
  • Errors can be quickly spotted - once an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs.
28
Q

Interpreters also have several disadvantages: (4)

A
  • Interpreted programs run slowly as the processor has to wait for each instruction to be translated before it can be executed.
  • Additionally, the program has to be translated every time it is run.
  • Interpreters do not produce an executable file that can be distributed. As a result, the source code program has to be supplied, and this could be modified without permission.
  • Interpreters do not optimise code - the translated code is executed as it is.
29
Q

Assemblers - what is its purpose

A

The purpose of an assembler is to translate assembly language into machine code.

30
Q

Fundamental difference between compiler and interpreters with assemblers

A

Whereas compilers and interpreters generate many machine code instructions for each high-level instruction, assemblers create one machine code instruction for each assembly instruction.

31
Q

Which of interpreters, compilers, assemblers translate their input into machine code directly ?
- what the other does?

A
  • assemblers and compilers translate their input into machine code directly
  • interpreters do not generate machine code directly (they call appropriate machine code subroutines within their own code to carry out commands)
32
Q

SPEC:

Machine code

  • expressed in?
  • specific to?
A
  • expressed in binary

- is specific to a processor or family of processors

33
Q

Do you know adv of low level programming compared to high-level?

A
  • Programs developed using low level languages are fast and memory efficient.
  • Programmers can utilize processor and memory in better way using a low level language.
  • There is no need of any compiler or interpreters to translate the source to machine code. Thus, cuts the compilation and interpretation time.
  • Low level languages provide direct manipulation of computer registers and storage.
  • It can directly communicate with hardware devices.
34
Q

Advantages of using high-level languages:

A

• easier to understand, so quicker and easier to program and debug
• easier for other programmers to understand – so code can be maintained more easily
• access to built in functions (such as print()) – meaning a complex set of low-level
processes can be turned into one command
• programs usually require fewer lines of code compared to assembly language
• access to built in libraries (such as random or time)
• easier to structure programs using iteration and selection
• can create subroutines to decompose code
• programs can be used on machines with different CPUs – so are more portable – they can
be moved between makes of computer much more easily
• help and support more available – better documented, help libraries and more popular

35
Q

Disadvantages of low level languages

A
  • Programs developed using low level languages are machine dependent and are not portable.
  • It is difficult to develop, debug and maintain.
  • Low level programs are more error prone.
  • Low level programming usually results in poor programming productivity.
  • Programmer must have additional knowledge of the computer architecture of particular machine, for programming in low level language.
36
Q

Disadvantage of high level langs

A
  • It takes additional translation times to translate the source to machine code.
  • High level programs are comparatively slower than low level programs.
  • Compared to low level programs, they are generally less memory efficient.
  • Cannot communicate directly with the hardware.
37
Q

Spec- what muster be translated

A
  • all programming code written in high-level or assembly language