1.2.4 Flashcards
low level and high level
we can sort all programming languages into 2 broad categories: H+L
Machine code: least abstract, closest to what actually happens in a computer, programs directly in 1s and 0s. Translate into matching electrical signals.
Assembly: uses mnuemincs (short words), each mnu matches specific sequence of 1s and 0s, 1-1 relationship, written in AL and translated by specific assembler.
high level: 1-m relationship, each instruction could give rise to many lines of am chine code.
high level languages
high-level programming language is written in language designed to be easily understood by humans. It uses syntax that is similar to human language to form instructions.
It must be translated into machine code before it can be run = compilation.
A single line of code can accomplish multiple tasks
easier to write programs in high-level languages than in low-level languages, syntax that is easy for humans to understand uses command words similar to natural human language.
Allow the programmer to focus on what the program is trying to achieve rather than how the computer or specific hardware operates
Source code is translated into machine code for the computer to process
portable. They can be compiled or translated to run on a wide range of computer architectures; they are not specific to a particular instruction set.
High-level languages come with libraries of functions that can be imported and used by the programmer. This means the programmer can take advantage of pre-written code.
Low level languages
Low-level languages are defined by the processor they are designed to run on; we can describe these languages as machine-oriented. They have no built-in functions and can access specific registers in the processor.
adv+dis of machine code and assembly code
programming paradigms
Programming paradigms are different approaches to using a programming language to solve a problem.
High level split into two broad categories - imperative and declarative - which can be broken down further into more specific paradigms.
imperative and declarative
IL use statements that change a programs state in the form of a sequence, selection, iteration etc. They consist of commands for a computer to perform and focus on describing how a program operates.
DL focus on what the program should accomplish.
imperative languages
two main paradigms that full under IL, procedural programming and object orientated programming.
Procedural programming is a type of imperative programming paradigm where a program is built from one or more subroutines (procedures, functions). Focus on telling a computer exactly what to do by way of step-by-step instructions.
It lays code out as a series of statements like sequence, selection, iteration.
OOP paradigms are a modern extension of the imperative programming approach that focuses more on a modular approach to programming.
Pl examples
Procedural languages use traditional data types such as integers and strings which are built into the language and also provide data structures like dictionaries and arrays.
Structured programming is a popular subsection of procedural programming in which the control flow is given by four main programming structures:
- Sequence
Code is executed line-by-line, from top to bottom.
- Selection
A certain block of code is run if a specific condition is met, using IF statements.
- Iteration
A block of code is executed a certain number of times or while a condition is met. Iteration uses FOR, WHILE or REPEAT UNTIL loops.
- Recursion
Functions are expressed in terms of themselves. Functions are executed, calling themselves, until a certain condition known as a base case (which
does not call the function) is met.
So procedural programming is suited to problems that can easily be expressed as a series of instructions using the constructs described above.
procedural paradigms vs object oriented
Describe how the operating system would use virtual memory to load program C.
Operating system uses area of secondary storage
as virtual memory.
- Move unused pages/parts (of program A and/or B) into virtual memory
- Load program C into (physical) memory.
Discuss the differences between assembly code and high‑level languages
Assembly code uses mnemonics to represent machine code instructions/opcodes.
High level languages use more natural/mathematical notation.
Assembly code consists of simple instructions
As such many more lines of assembly code are required to perform the same task as a few lines of a high level language.
Assembly code is specific to the instruction set of a given processor. High Level languages are not architecture specific.
Assembly code allows the programmer to choose the exact instructions so they can write code that is highly efficient.
It also allows them to have direct control of how memory is used via addressing modes.
Direct control of hardware.
High level language compilers have optimisers that can also try and do this (and in some cases may outperform a human writing in assembly code).
As high level code is more intuitive and easier to read it is easier to follow, debug and build as part of a team. It can also be written in a much shorter time frame.
The high level code can be recompiled for different architectures.
High level languages come in a variety of paradigms so
programmers can choose according to the problem/their preference.
Assembly language is best suited to situations such as:
-compilers or interpreters don’t exist for the target CPU i.e. embedded systems
-highest possible performance is critical
-memory is very limited.
For larger projects which don’t fall under the constraints above high level languages are likely to be preferable
declarative languages
two paradigms fall under DL: functional and logical.
Functional programming uses the concept of reusing a set of functions, which form the core of the program. Programs are made up of lines of code consisting of function calls, often combined within each other. Closely linked to mathematics.
Logic languages use code which defines a set of facts and rules based on the problem. Queries are used to find answers to problems.
mnemonics
Once an instruction is fetched it needs to be decoded before we can execute it. Involves splitting the binary that makes up the code into opcode and operand.
The opcode specifies the instruction to be performed. The operand holds a value
which is related to the data on which the instruction is to be performed.
Addressing modes allow for a much greater number of locations for data to be stored as
the size of the operand would otherwise constrain the number of addresses that could be
accessed. It specifies how the operand should be interpreted. The addressing mode is part of the opcode and there are four addressing modes:
- Immediate Addressing
The value in the address part of the instruction is actually the value to be used, so the memory doesn’t need to be searched to find the required value. e.g., add 10 is add 10. - Direct Addressing
The value in the address part of the instruction is a reference to the address in memory where the required value is located. e.g., find what is in the memory address location 10 ad add it to the acc. - Indirect Addressing
The value in the address part of the instruction is a reference to the memory location that contains the address in memory where the required value is located.
This mode of addressing memory is useful since it means larger address ranges can be useful to reference data and ins. - Indexed Addressing
An index register is used, which stores a certain value. The address of the operand is determined by adding the operand to the index register. This is necessary to add an offset in order to access data stored contiguously in memory such as in arrays.
OOP
Attempts to capture/group info, data and related code into structured items(objects). e.g. animal, car, data structure, account. Each object is repsonsible for its own data and operations performed on it. Objects interact with each other by sending/receiving messages.
adv:
once you define a class (deciding what attributes and methods it’ll have) it becomes easy to reuse that class and can create hundreds of objects of that class, also shareable to different projects
With inheritance, data analysis can be done in less time with precise bug free code
dis:
Slower programs than procedural based programs as they require more instructions to be executed