Hardware 2 Flashcards
Control Unit (CU)
The part of the CPU responsible for directing electrical signals to the computer, in order to execute program instructions.
Arithmetic Logic Unit (ALU)
The part of the CPU responsible for performing arithmetic and logical operations.
Registers
The CPU has its own memory, called memory registers. These are actually even faster to use than RAM because they are physically inside the CPU and therefore the electrical signals have a shorter distance to travel.
Size is dependent on architecture, i.e. 32-/64-bit systems.
Downsides of Registers
There are a limited number and they can hold an extremely limited amount of data.
Types of Registers
Special Purpose: Intended for one specific task
General Purpose: Can be used by programs as they’re compiled and turned into machine code to do all manners of tasks.
Extended Accumulator Register (EAX)
32-bit wide register Designed to be the "calculator" on the system Can reference portions of it: - AX for (lower) 16 bits - AH/L for higher/lower 8 bits
Extended Instruction Pointer (EIP 32-bit, RIP 64-bit)
Designed to hold the memory address of the next instruction to be executed. Used to direct the CPU to find the next bit of code.
Stack Pointer Register (ESP)
Contains a memory address which points to the top of the current stack frame in RAM.
Base Pointer Register (EBP)
Contains a memory address which points to the bottom of the current stack frame in RAM.
Source Index Register (ESI)
Typically used to hold a memory address of data when that data is being used as a source in an operation.
For example, if you are copying data from one location to another, ESI will contain the memory address of the data you are copying.
Destination Index Register (EDI)
Typically used to hold a destination memory address.
If you were to copy data from one location to another, EDI holds the memory address that the data is going to be copied into.
Fetch-Decode-Execute (FDE) Cycle
- The control unit ‘fetches’ the next instruction from RAM.
- The control unit ‘decodes’ the instruction and retrieves the necessary data from memory and places it into the arithmetic logic unit (ALU) of the CPU.
- The arithmetic logic unit (ALU) ‘executes’ the instruction, and operates on the data provided in the previous step.
- The arithmetic logic unit stores the result of the execution either in a memory register or RAM.
Sections of RAM
Stack & Heap
Stack
Very structured and orderly memory section
Program instructions are loaded onto the stack and each function is assigned a ‘stack frame’ (memory area). The stack frame contains local variables used by the function.
At the bottom of the stack frame is the return pointer.
When the CPU enters a function, it will save the previous value of EIP to the bottom of the stack frame
When the CPU gets a ‘return’ instruction, it will load the return pointer from the bottom of the stack frame into EIP and leave the function.
Heap
Unstructured area of memory that can be used to store data.
Slower to access than the stack, but you can store whatever you like without knowing beforehand the size of the data.