click below
click below
Normal Size Small Size show me how
1.2.4
| Question | Answer |
|---|---|
| Programming paradigms | The approach, style or pattern we follow when programming |
| Turing complete | when paradigms can complete any problem (ignoring practical constraints), making paradigms equal |
| Low-level languages compared to high level | Pros - More flexible due to direct memory access - More efficient - Less storage - Can be used in embedded programs Cons - Machine dependent - Harder to read/write/debug - Need detailed CPU architecture knowledge - Longer code |
| Machine dependent | only works on specific CPU architecture |
| Low level paradigms | Consist of opcode and operand Pros -Both have same execution efficiency -Produce precise, efficient code -Direct access to system-level features Cons -Machine-dependent -Hard to debug -Hard to understand, modify + maintain code |
| Machine code (Low level paradigms) | - Programs in 1s and 0s that translate to electrical signals - Closest to what actually happens on a computer |
| Assembly language (Low level paradigms) | - Short code words (mnemonics) that each matches a sequence of 1s and 0s - Translates by a specific assembler - One-to-one instructions - Opcodes are mnemonics |
| Declarative (High level paradigms) | Don’t say how to solve a problem, but says what needs to be done |
| Imperative (High level paradigms) | Control the state of the program (sequence, iteration etc) through instructions that solve the problem, focus on describing how a program operates - Procedural - Object-oriented |
| Procedural (Imperative) | - Give the computer step-by-step instructions to solve a problem - Instructions are grouped into subroutines - Sequence, selection + iteration - Stored in variables that can be passed to subroutines |
| Object-oriented (Imperative) | - Objects are created that can interact with each other - Sequence, selection, iteration, inheritance, objects, classes, - Stored in attributes concealed by encapsulation - Classes, methods and instances |
| LMC | little man computer: Each processor family has its own assembly language opcode set. We use little man computer (LMC) opcode set that uses 11 opcodes. Each line can have up to 3 parts: a label, the mnemonic, the data. |
| ADD (LMC) | Add |
| SUB (LMC) | Subtract |
| STA (LMC) | Stores ACC contents in memory |
| LDA (LMC) | Loads memory value to ACC |
| BRA (LMC) | Always branch to a location in the computer (iteration) |
| BRZ (LMC) | Branch to a location if ACC contents are 0 (iteration, selection) |
| BRP (LMC) | Branch to a location if ACC contents are positive (iteration, selection) |
| INP (LMC) | Input |
| OUT (LMC) | Output ACC contents |
| HLT (LMC) | End program (halt) |
| DAT (LMC) | Memory location label |
| Memory addressing | ways of accessing memory in low level languages |
| Addressing modes | determine the way the operands of an instruction are interpreted - Immediate - Direct - Indirect - Indexed |
| Immediate addressing (addressing modes) | the operand is the data to be used, not an address |
| Direct addressing (addressing modes) | operand is the address of the data to be used |
| Indirect addressing (addressing modes) | operand is the address where the address of data to be used is - Useful where there are not enough bits to represent addresses |
| Indexed addressing (addressing modes) | operand is added to value in IR to give the memory address of the data to be used - Useful when you want to visit several consecutive addresses, as IR is incremented |
| IR | index register: stores a value to be used as a base address to add to the operand |
| OOP | object-oriented programming: attempts to group information, data and related functionality (code) into structured items known as objects |
| Objects (OOP) | instances of classes that can store data and perform actions on this data |
| Instantiation (OOP) | the process of creating an object from a class |
| Classes (OOP) | templates, with attributes and methods defined within it, that create objects - Easy to reuse, and create many objects from it Four parts: - Class name - Constructor method - Its attributes - Its methods |
| Constructor method (Classes) | runs when an object of that class is instantiated |
| Attributes (Classes) | ‘properties’ of the class (like variables) |
| Methods (Classes) | code that allows attributes to be changed (like subroutines) |
| Classes code example (OOP) | Class toyTank #Class name Private color #Attributes #Constructor method Public procedure new (givenColor) Color = givenColor Public procedure getColor() #Methods print(color) Public procedure setColor(newColor) Color = newColor |
| Encapsulation (OOP) | hiding the values or internal state of an object, preventing direct access - Encapsulated attributes are only accessible/changeable via the methods - This is what the ‘private’ key term means - Allows validity checks inside the methods |
| Inheritance (OOP) | Inheritance: a class obtains attributes and methods defined in another class, as well as being able to define its own methods and attributes The first line of code would then be: Class toyTank inherits Models |
| Superclass/base class (Inheritance) | class others inherit from |
| Subclasses/derived classes (Inheritance) | classes that inherit from superclasses |
| Overriding (Inheritance) | when a subclass writes a new method under the same name as in a super class that method is used instead of the old one To use the old one, the key word .super is used: tankOne.super.getName() |
| Polymorphism (OOP) | two different objects respond to the same command in different ways (e.g. overriding) |