Computer Science Test 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Mid term CS study sheet

CPU
● The CPU contains the basic arithmetic, logic, and control elements of a
computer required for processing data. ‘The computer’s brain is a popular
phrase’.
● The control unit (CU) is a CPU component that directs the operation of the
processor, and it decides what's allowed in the CPU and what isn't.
● An arithmetic logic unit(ALU) is a digital circuit that performs arithmetic and
bitwise operations on integer binary numbers. (performs arithmetic
calculations).

Memory
● Primary memory is computer memory that a processor accesses directly. For
example, it allows a processor to access running execution applications.
● Secondary memory is the various storage media on which a computer can
store data and programs. Unfortunately, secondary memory is quite large and
slow.
● Primary memory usually refers to Random Access Memory (RAM) and
registers. In contrast, secondary storage relates to hard disk drives, solid-
state drives, removable “USB” drives, CDs, and DVDs.

Buses
● Buses allow communication between the components in a computer.
● The purpose of an address bus is to identify the address of the location in the
primary memory. CPU -> RAM one-way.
● The data bus allows the data transfer to the CPU.
● Control bus - carries signals of the decision made by the CU to determine
what goes in and out.

Registers
● memory address register (MAR) - holds the address of the current instruction
that is to be fetched from memory.
● The Memory Data Register is the register of a computer's control unit that
contains the data to be stored.
● The program counter (PC) is a register that manages the instruction’s memory
address to be executed next.
● The current instruction register (CIR) is the part of a CPU's control unit that
holds the instruction currently being executed or decoded.
● In the CPU, the accumulator is a register in which ALU results are stored.

Fetch execute cycle


1. The processor checks the program counter to see which instruction to run
next.
2. The program counter gives an address in the memory of where the next
instruction is.
3. The processor fetches the instruction value from its memory location.
4. Once the instruction has been fetched, it needs to be decoded and executed.
For example, this could involve taking one value, putting it into the ALU, then
taking a different value from a register and adding the two together.
5. Once this is complete, the processor goes back to the program counter to find
the next instruction.

Fetch execute cycle (SAMI)


● Fetch → decode → execute → writeback
● Fetch: the control unit fetches the data
● Decode: The control unit makes decodes and prepares it for processing.
● Execute: The ALU executes/processes the decoded instruction.
● Writeback: sends the result back to the memory from which the data was
initially taken; the CPU is responsible for the writeback.

Variables

● A storage area for values and information to be kept in.


● Variables are soft coded (can be rewritten).
● In computer programming, a variable storage location is paired with a
symbolic name, which contains the information referred to as a value.
● The variable Must be appropriate/related to the value being stored in it.
● Variables can’t have spaces and are case sensitive.
● Variables can be reused as shortcuts in code.

Loops:

● A for loop is a loop which repeats a specific number of times.


● A for loop will be used if we know exactly how many times we want to repeat
the program.
● This would be useful if we wanted someone to input several orders for
Starbucks, but the max order is four drinks per person.

● A while loop is a repeated line of code, which keeps repeating until a


condition is met.
● A while loop will be used if we don't know how many times the program has to
be repeated,
● This would be useful; for example, when asking for an input to a specific
answer, the loop can run until the correct answer is input.

● Iteration: a loop/a use of a loop that goes over something multiple times.
Programing construct:
Selection:
● If statements help us run a particular code only when a specific condition is
met.
● For example, if you want to print a message on the screen only when a
condition is true, you can use the if statement to achieve that.

Sequencing:
● Sequencing: executing values stored in a variable in order (line by line
execution of code)
● Sequences such as lists can include more than one value of data into one
variable, but “ [“ ”] ” is used instead of “ ( ) “, and commas should be used too
between each variable.
● Python uses 0 indexing, meaning it starts counting from 0.
● Lists can be updated like a normal variable could.
● A value can be overwritten in a list variable.

To overwrite a value in a list you:


Names = [“doody”, “Sami”, “Abdulrahman”]
Names[0] = “doody”
print(Names) : doody, sami, abdulrahman

● You can also show sequencing as:


Names = [“yes, No”]
print(Names[0])
Print (Names[1])

List properties:
● When the length function is used on a list, it returns the number/amount of
values in a list number of values instead of the characters. e.g.
Things = [“pencil” , “eraser”]
print(len(things)) → output is 2
● Dot notation: a way to call specific methods on specific objects.
● Lots of dot notation methods can be used on a list.
● .append is how we add items to our list, but they always get added to the end
of the list.
● .insert(): allows you to add specific items to the list in specific areas.
● .pop: removes the last item from the list.
● .remove: removes the first value from the list.
● .reverse(): reverses the order of the list in range (e.g. 0-3 → 3-0)
● .sort(): sorts the elements of an array (list) in place and outputs the sorted
array.
● .count(): says the number of times a specific value appears in a list.

Note
● Immediate access store: registers or primary memory.

You might also like