SLR 7 + SLR 8 - TYPES OF PROGRAMMING LANGUAGE + PROGRAMMING PARADIGMS Flashcards
What are the 2 types of programming language?
- high level languages
- low level languages
What are some examples of low level languages?
- machine code
- assembly language
What is used to translate assembly language into machine code?
an assembler
LMC instruction set (11)
- ADD (add)
- SUB (subtract)
- STA (store)
- LDA (load)
- BRA (branch always)
- BRZ (branch if 0)
- BRP (branch if positive)
- INP (input)
- OUT (output)
- HLT (end program)
- DAT (data location)
What are the 4 methods of addressing?
- immediate
- direct
- indirect
- indexed
What is immediate addressing?
- value in the address part of the instruction is the actual value to be used (so memory does not need to be searched to find that required value)
- eg: ADD 10 literally means add 10 (not add value stored in memory address 10)
What is direct addressing?
- value in the address part of the instruction refers to the address in memory where the required value is located
- eg: ADD 10 means add the value that’s located in memory address location 10
What is indirect addressing?
- value in the address part of the instruction refers to the memory location that contains the address in memory where the required value is located
- this is useful as it means larger address ranges can be used to reference data and instructions
- eg: ADD 10 means add the value that’s located in the memory address location that was stored in memory address location 10
What is indexed addressing?
- a method where the final memory address is calculated by adding a constant value (the offset) to the contents of an index register
- this allows efficient access to data stored in consecutive memory locations, such as arrays
- eg: the index register contains the value 5. the instruction ADD 10 refers to memory location 10 + 5 = 15. the CPU retrieves the value stored at memory location 15 and adds it to the accumulator (or the current working register)
What are the main programming paradigms?
- low level languages,
- object-orientated languages
- declarative languages
- procedural languages
- functional languages
What are Turing complete languages?
programming languages that can solve all problems that a computer is able to solve (most programming languages in most programming paradigms)
Why do we need different programming paradigms?
some problems are better suited to being solved using a certain paradigm
What are the 2 types of high level languages?
- imperative (focus on describing how a program operates)
- declarative (focus on describing what the program should accomplish)
What are the 2 main paradigms that fall under imperative languages?
- procedural programming
- object-oriented programming
What are features of procedural languages?
- variables
- constants
- sequence
- selection
- iteration
- subroutines
- string handling
- operators
What is object-oriented programming (OOP)?
a programming paradigm that attempts to capture or group info into structured items (objects)
What is a class?
defines what attributes and methods an object of a certain type should have (template so every object made from that class has the same attributes
What are the 3 sections of a class diagram?
- class name
- attributes (all info shared by any any object of this class type)
- methods (code associated with a class that allows you to change/access attributes)
What is instantiation?
the process of creating an object from a class template
Example of code to define a class (pseudocode)
class (class name) (eg: toyTank)
private colour
private name
public procedure new (givenColour , givenName) colour = givenColour name = givenName end procedure public procedure getColour() print("my colour is " + colour) end procedure public procedure getName() print("my colour is " + name) end procedure public procedure setColour(newColour) colour = newColour end procedure public procedure setName(newName) name = newName end procedure endclass
Example of code to create objects from the class template (pseudocode)
(objectone) = new (class name)(“(colour)”, “(name)”)
(objecttwo) = new (class name)(“(colour)”, “(name)”)
(objectthree) = new (class name)(“(colour)”, “(name)”)
eg:
tankone = new toyTank(“blue”, “trevor”)
tanktwo = new toyTank(“red”, “tim”)
tankthree = new toyTank(“green”, “tony”)
Example of code to get and set object names and colours (pseudocode)
(objectone).getName
(objectone).setName(“(name)”)
(objectone).getColour
(objectone).setColour(“(colour)”)
eg:
(tankone).getName
(tankone).setName(“tom”)
(tankone).getColour
(tankone).setColour(“yellow”)
What is inheritance?
- a way of creating classes that share most of the same features as another class
- subclass inherits details of superclass and adds additional attributes and methods required
Code for inheritance (pseudocode)
class (subclass name) inherits (superclass name)
etc….
endclass