The Basics

<aside> 💡 CPU/processor and main memory (RAM) are connected by a bus (set of parallel wires), as per the Von Neumann architecture.

</aside>

<aside> 💡 ALU (Arithmetic Logic Unit) - circuit in the CPU that performs arithmetic (+, - , x, ÷), relational (<, >, =), and logical (AND, OR) operations.

</aside>

The Instruction Cycle

<aside> 💡 Instruction Pointer (IP) - contains address of the next instruction to be executed Instruction Register (IR)- stores current instruction we are dealing with

</aside>

<aside> 💡 1. Fetch Get the next instruction to be executed. The instruction pointer (IP) contains the address of that next instruction and puts it in the instruction register(IR).

2. Decode Figuring out what operations this instruction requires + get the operands (which can be in registers or RAM).

3. Execute Perform the instruction. For instance, if our instruction was adding two numbers, the ALU would be needed to perform this instruction.

</aside>

Screen Shot 2022-02-15 at 10.03.54 AM.png

Four Steps of Compilation

<aside> 💡 1. Preprocessor The preprocessor takes any header files, directives, (i.e #include, #define, #ifndef)

2. Compiler The complier takes C/C++ (source code) and converts that to assembly code. The complier decides what registers to use (following the appropriate calling convention).

3. Assembler The assembler converts assembly code into machine code.


4. Linker The linker links object/library files and creates an executable

</aside>

Screen Shot 2022-02-15 at 8.40.37 AM.png

High-Level Languages & Assembly Code

<aside> 💡 Why is source code (C/C++ code) machine independent, but assembly code and machine code are machine dependent?

Source code is machine independent because they can be run on any computer despite its architecture. For instance, C/C++ code can run on a computer with an x64 or ARM architecture. However, assembly code and machine code are machine dependent as they can only be run on a computer’s ISA. For instance, ARM assembly/machine code can be run on computers with ARM architectures, but not computers with x64 architectures.

</aside>

<aside> 💡 An executable can only be directly run on a processor if the executable consists of machine code that that processor understands.

For instance, an x64 processor can only directly run an executable that consists of x64 machine code.

</aside>

Memory Hierarchy

Screen Shot 2022-02-15 at 8.27.02 AM.png