3.3 Programming Languages (B03) Flashcards

1
Q

how does CPU run high level code?

A

Your high level code is translated to ‘low level’ instructions by a compiler or interpreter.
An assembler then converts the assembly code instruction into binary code (known as machine code and sometimes as object code) that the CPU can understand.

Some translators convert your high level code straight to machine code.

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

features of high level languages

A

More ‘English-like’ and hence easier to learn.

Less error-prone.

Easier to debug and to maintain.
Quicker to write – this can be more important in the business world than having code that runs as fast as possible.

Can work on different machines (portable).

A translator (interpreter or compiler) is required to convert the code into low level code before it can be run.

There are built-in functions for programmers to use. For example in Python, using the built-in function print makes the Python code output something to the screen. The programmer does not need to know the complexity of how the print statement is executed, just that it will do the job.

Similarly, for high-level languages, there are libraries of functions that can be imported to solve specific problems. For example in Python, you can import the random module (library) which lets you carry out various functions related to random numbers and all without needing to know exactly what the computer is doing.

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

features of low level languages

A

One assembly code construction = one line of machine code, doing one specific action.

Assembly code instructions are specific to a particular machine/CPU architecture.

Programmer needs to know about specific operations of the CPU, e.g. how memory is managed.

More control over what the hardware does, therefore can be more efficient.

Can be executed directly without needing to translate/interpret.

Difficult to manage, read or update code.

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

key difference between high- and low-level languages (speed and why)

A

High level languages are friendlier to read, but programs run more slowly because the code structure is based on a human-friendly structure.
In contrast, programs written in low level languages can run very quickly as it is based on the computer’s hardware architecture.

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

exam question!

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

machine code

A

the lowest level programming language - written in binary

commands that can be directly executed by a processor

There is a 1-1 relationship between what physically goes on inside a computer and a single instruction in machine language

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

instruction set

A

all the different machine code instructions a microprocessor (CPU) can execute

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

machine code pros and cons

A

Advantages:
Programs can execute very quickly.
Programs take up less memory.

Disadvantages:
Slow and difficult to write.
Error-prone.
Hard to remember.
Machine code is specific to each single machine.

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

assembly language

A

low-level language written in mnemonics

usually a one-to-one relationship between an assembly instruction (e.g. MOV) and the corresponding machine code

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

pros and cons of assembly language

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

how does writing code differ in high vs low-level languages

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

tasks for which high- or low-level languages are better suited

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

compilers vs interpreters (seperate file?, when, how often, errors)

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

assembler

A

Translate assembly language into machine code. Computers do not understand Assembly, hence the need for it to be converted.
Each different type of machine/processor requires an assembler of its own.

(special type of compiler)

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

compiler

A

translate a program written in one language into another language
source code -> compiler -> object code

machine code is saved and stored as an executable file (.exe) separately to the high-level code. This means users do not have access to the source code, preventing them editing or stealing it.
compiler is not needed to run the object code, so it easy to distribute the program – users just have to execute the final file
difficult to test line by line, but: points out all syntax errors
C++ is a compiled programming language.

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

interpreter

A

translates code into machine code, instruction by instruction – the CPU executes each instruction before the interpreter moves on to translate the next instruction
does not create an independent final set of source code – it takes a line of source code at a time and converts it to machine code (which the computer runs straight away)

Interpreted languages include JavaScript, PHP, Python and Ruby.

17
Q

using compilers vs interpreters