Computer Science – Unit 1 Pointers
Key Definitions:
Problem-solving – refers to the systematic approach of brainstorming and exploring possible
solutions to the general issue identified.
Algorithm – refers to the finite number of precise steps in which the flow of control of processes
is done in a step-by-step manner to solve the general problem presented.
CPU – the central processing unit (CPU) is a microprocessor consisting of millions or billions of
transistors, resistors, and diodes that are used to execute high-speed tasks for each clock cycle,
serving as the logical brain of the computer system (handles program logic through arithmetic
and comparative operations).
Registers – small capacity, high-speed primary memory units located on the CPU, holding
addresses/instructions temporarily (serving as buffers) for quickly executing the instruction
cycle.
Instruction set – refers to the different types of processes that a CPU can perform during the
machine cycle. It speaks to the lexicon of possible instructions that the CPU can perform within
it’s circuitry. For example, arithmetic, logic, and data-transfer operations can be executed based
on the system-architecture. Notably, instruction set architecture elaborates on this definition by
detailing how the CPU interacts with hardware components (main memory) to execute
instructions within the operating system’s lexicon (x86/ARM).
Instruction format – refers to the structure of an instruction in main memory to be decoded by
the control unit based on system architecture (x86, ARM). An instruction format features binary
by Leo~
segments that represent addressing modes (immediate, direct, and indirect), opcode (details the
operation for execution like ADD, MUL, MOV, PUSH), and operands (computable terms like
immediate values or registers holding pointers to values).
Byte – the smallest number of bits representing a single character, typically (7-8 bits). It is the
smallest addressable unit of data within most computer systems (meaning it holds part of an
address).
Word size – refers to the standard number of bytes (chunks) that can be processed within a
single operation at a single time by CPU components (ALU, Registers).
Features of main memory:
RAM – Random Access Memory
1. Volatile memory (losses data once powered off)
2. Used to store data (instructions/addresses) to be processed by the CPU.
ROM – Read-on Memory
1. Non-volatile memory (retains data even after powered off)
2. Used to store system boot information (BIOS/UEFI)
PROM – Programmable Read-on Memory
1. Non-volatile memory (retains data even after powered off)
2. Used to store system boot information (BIOS/UEFI)
by Leo~
3. Can be programmed ONCE after system setup (after first write, fuse will blow, and other
attempts will fail)
EPROM – Erasable Programmable Read-on Memory
1. Non-volatile memory (retains data even after powered off)
2. Used to store system boot information (BIOS/UEFI)
3. It can be reprogrammed MORE THAN ONCE but uses ultraviolet radiation to clear the
boot information (takes up 20 minutes, quite slow).
EEPROM – Electronically Erasable Programmable Read-on Memory
1. Non-volatile memory (retains data even after powered off)
2. Used to store system boot information (BIOS/UEFI)
3. It can be reprogrammed MORE THAN ONCE by using electrical signals.
Control Structures:
i) Sequencing – involves instructions carried out in a step-by-step manner. Delving
deeper, it speaks to code following the imperative programming paradigm that details
how the program changes throughout execution via assignment or the other two (2)
listed control structures.
ii) Selection – involves instructions carried out by a condition. Detailing more, it entails
the use of blocked segments of code that will only be executed based on a specific
variable/expression state (compared through the use of relational operators).
iii) Iteration – involves instructions carried out by a loop. Elaborating further, it pertains
to bounded loop structures executing code segments a definite number of times, or
unbounded blocks of code only terminating after the sentinel condition is met.
by Leo~
Instruction Cycle/Machine Cycle:
i) Fetch – the Control Unit (CU) signals the Program Counter (PC) to retrieve the
address of the next instruction to be executed from main memory down the address
bus. After that, the address is copied to the Memory Address Register (MAR) and
then the Current Instruction Register (CIR) is flagged to fetch the instruction located
at the address of the MAR. Lastly, the PC increments to the next address.
ii) Decode – the CU will now evaluate the instruction stored in the CIR by using the
system-architecture-based instruction format (different method of instruction
processing; x86 vs ARM-64). The instruction is analysed for its addressing mode
(immediate, direct, or indirect) to decipher whether to progress to execution using the
opcode (ADD, MUL, PUSH, MOV) and operands (immediate values or registers
storing addresses).
iii) Execute – the CU signals the relevant register to process the decoded instruction and
will write the computed information back to main memory via the Memory
Buffer/Data Register (MBR/MDR). However, if the instruction required to fetch data
like loading the value stored at an address into a register, the MDR can also read the
corresponding data stored in main memory. For instance, LOAD R1, 0x1000.
Steps in Problem-Solving:
1. Problem Definition – involves explicitly documenting/noting the problem statement
for the identified issue for unambiguity. Moreover, it also features a general solution to
resolve the problem, and some functional/non-functional requirements are listed.
by Leo~
2. Problem Analysis – involves analysing the general solution identified to create an
algorithm (pseudocode, flowchart, narrative) to get a better understanding of how it will
be implemented using programming languages.
3. Identify & Evaluate Possible Solutions – involves brainstorming for other plausible
solutions to the problem statement and categorizing them for their advantages and
disadvantages to be justified in the next stage.
4. Select and Justify the Optimal Solution – at this stage, the programmer selects each
conceptualized solution and justifies the best solution by on weighing advantages
versus disadvantages in relation to the requirements previously mentioned.
5. Implementation & Review – the last stage entails the programmer converting the
algorithm to a programming language. Furthermore, it heavily features maintenance of
program state by testing/debugging variables and how they interact with each other in
executing the function/non-functional requirements. Notably, this is typically done using
a test plan to further add improvements to the final implementation.
Translation Process:
1. Lexical Analysis – this compilation stage features the lexer (lexical analyzer) breaking
down program code into tokens categorized by a symbol table of deemed identifiers
(variables, expressions, data structures), scope (global vs local), data types, memory
addresses, and other information (like function arguments). Moreover, it also removes
whitespaces and comments before proceeding to the next stages that will reference the
symbol table generated.
2. Syntax Analysis – this stage in the translation process speaks to the use of the symbol
table to generate concrete syntax trees (CSTs) and/or abstract syntax trees (ASTs).
by Leo~
Adding, syntax trees are used to represent blocks of code using nodes (of identifiers) and
ends (establishing parent-child relationships). Importantly, the syntax analyzer (parser)
evaluates whether or not code fragments are grammatically correct, adhering to the
programming language rules. These syntax trees used will either represent the entire code
using keywords and parentheses (CST) or abstract these concepts into phrases like
Variable, Expression, ConditionExpression, and Assignment. Typically, CSTs are used in
this stage whilst ASTs are used in semantic analysis for efficiency.
3. Semantic Analysis – this stage uses the semantic analyzer to annotate syntax trees (like
ASTs) with error messages due to type mismatch errors (unexpected variable used),
uninitialized variables used before assignment, or division by zero (as examples).
4. Intermediate Code Generation – here, the syntax tree (likely AST) is converted into an
intermediate representation (IR) that lies between a high-level code (human-readable) and
a low-level code (machine-readable). This IR involves abstracting complex high-level
code fragments through the use of explicit address formats (like Three-Address-Code;
TAC) consisting of assignment of temporal variables (t1, t2, t3…), “goto” conditional
branches, and operator keyword (op) [not needed, best to research this part if you’d
like]. This serves to make code optimization much easier when removing inefficient code
elements.
5. Code Optimization – now, this stage makes the IR more efficient in memory allocation
and code abstraction through methods like common sub-expression elimination
(eg., a = b + c and b = b + c is abstracted to a = b), dead code elimination (revoked
segments not influencing output), and strength reduction (replaces expensive
by Leo~
operations, for instance, multiplication being swapped for addition in certain contexts for
improved efficiency).
6. Code Generation – finally, object code [instructions] (in assembly or binary) is
generated from source code and header files/libraries, based on system-architecture
governing instruction processing (x86, ARM), and is stored in object (.o) files to be
linked into an executable file afterwards. Notably, assembly is generated before
converting to binary via an assembler in modern compilers as it is much harder to directly
convert the IR into binary.
Paradigms refer to the method involved in solving a task. Programming paradigms refer to the
way in which programs are written to solve general problems. There are two paradigms that
govern the other (3) considered paradigms on the syllabus.
Fundamental Paradigms:
1. Imperative Paradigm – telling the program explicitly HOW the solution is to be
implemented. Elaborating further, it details how the program should change it state in a
step-by-step manner via common methods like assignment, selection and iteration
constructs.
by Leo~
2. Declarative Paradigm – specifying WHAT the desired outcome is, rather than detailing
the steps in how to achieve it. It abstracts the program state and its control flow, typically
through immutability and the absence of side-effects (of variables), as seen in the
functional paradigm; only one considered in syllabus.
Based on Imperative Paradigm:
1. Object-oriented paradigm – method involves using real world classes/objects that
operate with certain behaviours grouped into base-classes/super-classes (like Customer
and Animal) that can be used in sub-classes/derived classes (like Jane Doe and Dog) via
inheritance and modified distinctively through polymorphism (assigning unique
attributes to objects, for e.g., Dog is an animal that barks whilst Cat is an animal that
meows). Hence, the integrity of local attributes/variables are important within
methods/functions, and are accessed using getters or setters, fostering encapsulation
(controlled access) and preventing overridden information.
2. Procedural paradigm – procedural paradigm follows the imperative paradigm by
utilizing functions/procedures in the step-by-step explanation of how the program should
change its state. Notably, functions also control how variables interact with one another
by using global and local scopes, ensuring information integrity (changes only as
intended by programmers; not overridden by other variables unknowingly).
Based on Declarative Paradigm:
1. Functional paradigm – functional paradigm is declarative because it uses
mathematical-like pure functions that simply gives the same desired output from
by Leo~
every repeated input without detailing the mathematical method. Here, variables
(immutable) will not change their state based on conditions or loops but depend
only on the input provided. Moreover, functions are considered as high order
because they can be used as arguments or return values for other functions.
by Leo~