1.2.4 Types of Programming Language Flashcards
Procedural Programming
Uses a sequence of instructions which are carried out in a step by step manner.
Procedural Programming disadvantages
- May be inefficient when trying to solve certain problems.
Procedural Programming advantages
- It can be applied to a wide range of problems
- It is easy to write and interpret.
Why is assembly language easier to use than machine code?
It uses mnemonics rather than binary
Why are the commands that assembly language uses processor specific?
It directly interacts with the CPU’s special registers.
Mnemonic: ADD
Add value at given memory address to the value in the accumulator
Mnemonic: SUB
Subtract the value at the given memory address from the value in the accumulator
Mnemonic: STA
Store the value in the accumulator at the given memory address
Mnemonic: LDA
Load the value at the given memory address into the accumulator
Mnemonic: INP
Allow the user to input a value which will be held in the accumulator
Mnemonic: OUT
Outputs the value currently held in the accumulator
Mnemonic: HLT
Stops the program at that line, preventing the rest of the code from executing.
Mnemonic: DAT
Creates a flag with a label at which data is stored
Mnemonic: BRZ
Branches to a given address if the value in the accumulator is zero. This is a conditional branch.
Mnemonic: BRP
Branches to a given address if the value in the accumulator is positive. This is a conditional branch.
Mnemonic: BRA
Branches to a given address no matter the value in the accumulator. This is an unconditional branch.
What does 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.
What does the addressing mode do?
Specifies how the operand should be interpreted.
What is the addressing mode part of?
The opcode.
Immediate Addressing
The operand is the actual value upon which the instruction is to be performed, represented in binary.
Direct Addressing
The operand gives the address which holds the value upon which the instruction is to be performed. This is used in LMC.
Indirect Addressing
The operand gives the address of a register which holds another address, where the data is located.
Indexed Addressing
- An index register is used, which stores a certain value.
- The final address of the data is determined by adding the value in the index register to the operand.
Class
A template defining the attributes and methods that can be used to create a type of data known as an object.
Object
An instance of a class, with a set of attributes and methods.
Setter
A method that sets the value of a particular attribute.
Getter
A method which retrieves the value of a given attribute.
Why use getters and setters?
To ensure attributes cannot be directly edited and accessed.
What does Encapsulation do?
It protects attributes from being directly accessed.
How is Encapsulation implemented?
By only allowing class methods to access data in an object’s attributes.
Constructor
Creates an instance of a class.
Inheritance
The concept of subclasses inheriting the methods and attributes of its parent class.
Polymorphism
Objects of different classes can use the same method to perform an action.
OOP Advantages
- Allows for a high level of reusability
- Classes can be used across multiple projects
- Encapsulation makes the code more reliable by protecting attributes from being directly accessed.
- Modular structure makes it easy to maintain and update
OOP Disadvantages
- Different style of programming, and so requires an alternative style of thinking.
- OOP is not suited to all types of problems. Where few components are reused, OOP may result in a longer more inefficient program
- Generally unsuitable for smaller problems.