Intro to Computer Organization: CPU, Stored Programs, and Data Transfer (Opcodes and Store Instruction)
CPU and Memory Organization
- The central processing unit (CPU), also called the processor, is the brain of the computer. In the example, it’s described as a small unit roughly two inches by two inches.
- The register unit is part of the CPU and provides fast, small-scale storage for data the CPU is actively working with.
- Memory (main memory) stores both data and instructions. The system is described in the context of a simple machine to illustrate concepts.
- Early hardware was highly machine-dependent: if you only had additions hard-wired, you’d need to rewire the CPU to perform other operations.
- This changed with the Von Neumann approach: a machine that can execute different instructions without hardware changes by loading programs into memory.
- The same CPU can run any program by changing the program encoded in memory.
- A program is encoded as bit patterns and stored in main memory, enabling flexible computation on the same hardware.
- The memory and CPU cooperate to perform computations: data stored in memory must be brought into the CPU (in registers) to be processed by the CPU.
Von Neumann Stored-Program Architecture
- The breakthrough: you don’t have to alter hardware to execute different types of instructions; you change the memory-resident program instead.
- Memory holds both data and instructions because of the stored-program principle.
- The control unit coordinates the flow of instructions from memory to the CPU for execution.
- Stored programs enable general-purpose computing on a single hardware platform.
Stored Program and Machine Instructions
- Instructions come in a set of machine-level operations. One broad category is data transfer: copying data from one location to another.
- Other instruction types perform computations or control flow; the complete set defines what the CPU can do.
- The control unit orchestrates these operations, effectively directing the CPU to fetch, decode, and execute instructions stored in memory.
- The architecture emphasizes the linkage between memory storage and CPU processing: the program and its data live in memory, while the CPU executes the instructions.
Step-by-Step: How addition happens in memory- resident data
- High-level idea: two values stored in memory must be retrieved, added by the CPU, and the result stored back.
- The CPU performs the actual addition; data resides in memory until moved into registers for processing.
- Steps to add two values stored in memory:
- Step 1: Load the two operands from memory into registers (e.g., registers A and B).
- Step 2: The ALU (arithmetic logic unit) within the CPU computes the sum: A+B=R, where A and B are the register values and R is the result in another register.
- Step 3: Store the result from the result register back into a register or memory as needed (e.g., into a destination register, and potentially back to memory).
- The CPU’s architecture is often described as having a bridge between memory and its own fast storage (registers) to perform operations.
- The example emphasizes that the CPU is the “brain,” while memory holds data and programs to be operated on.
A Simple, Toy Machine: Memory, Registers, and Opcodes
- The toy machine has: $256$ memory cells and $16$ registers.
- Memory cells provide addressable storage for data and instructions.
- Registers (denoted with R) are the CPU’s fast, short-term storage for immediate data used in calculations.
- An example opcode discussed is the number $3$, which represents a store operation in this encoding scheme.
- The description uses a format like: "three r x y" meaning: opcode = $3$, source register = $r$, target address = $(x, y)$, i.e., a memory address.
- The instruction encodes a data-movement operation: store the contents of a CPU register into a memory location.
- In this notation, $R$ stands for a register, and $x$ and $y$ denote memory addresses.
- There is discussion about concrete examples and how to read them:
- Example interpretation: "store 15 in the address 01" means: take the contents of register $15$ and write that value into memory location $01$.
- It’s important to note that the number $15$ here is the register number, not the literal value stored in the register.
- The value stored into memory is whatever is currently contained in the specified register, not the literal number $15$.
- The distinction between registers and memory is emphasized: the CPU needs its own fast storage (registers) separate from memory, so data can be operated on quickly.
- Registers are fast but limited in size; memory is larger but slower to access.
- The practical purpose of a store instruction (opcode $3$) is to move data from a register into memory, making the result available to subsequent instructions or separate programs.
Detailed interpretation of the store instruction (opcode 3)
- The encoding described: "3 r x y" where
- 3 = opcode for store
- r = source register containing the value to store
- x, y = memory address fields that specify where in memory to place the value
- The narrative includes a concrete example: "store 15 in the address of 01". Interpreted literally:
- The value in register $15$ is written to memory location $01$.
- Note: It is the contents of register $15$ being stored, not the literal number $15$.
- Clarifications about the fields:
- r is a placeholder for the source register (e.g., r could be any register number, such as 7, 15, etc.).
- x and y specify the memory location; the exact format depends on the chosen addressing scheme (here they’re presented as two fields representing a memory address).
- Why the destination is memory and not another register:
- The CPU uses registers as fast scratch space for immediate computation, but the long-term/store results must reside in memory to be used by other instructions or to persist across operations.
- Memory serves as the main storage, while registers provide the fast working area for the CPU’s operations.
- A note on possible exam confusion from the dialogue:
- The speaker asks whether numbers like 7 or 15 refer to register numbers or literal values; the answer is that they denote register identifiers, and the actual data depends on the contents of those registers at the time of execution.
Key concepts and terminology recap
- CPU (Central Processing Unit): executes instructions and performs arithmetic and logic operations.
- Register: a small, fast storage location inside the CPU for intermediate data.
- Memory (main memory): larger storage for data and program instructions.
- Control unit: part of the CPU that coordinates the fetch-decode-execute cycle.
- ALU (Arithmetic Logic Unit): the CPU component that performs arithmetic and logical operations.
- Stored-program architecture (Von Neumann): the program is stored in memory and executed by the CPU without hardware changes.
- Opcode: the numeric code that identifies an instruction (e.g., $3$ for store in this example).
- Data transfer instruction: a type of machine instruction that moves data from one location to another (e.g., from a register to memory).
- Addressing fields: in a simplified encoding, registers (R) and memory addresses (x, y) specify where data comes from and where it goes.
Connections to foundational principles
- Software-driven hardware flexibility: stored programs enable a single hardware design to run many different tasks.
- Separation of concerns: data and instructions can reside in memory while the CPU handles computation and data movement.
- Performance considerations: moving data from memory to registers is a critical operation for CPU efficiency; registers provide fast access paths.
Practical implications and takeaways
- To perform arithmetic on values stored in memory, data must be loaded into registers, processed by the ALU, and the result stored back to memory if needed.
- The store instruction demonstrates how data can be moved from registers into memory, enabling persistence and communication between different parts of a program.
- When reading a toy encoding like "3 r x y":
- Interpret as: store the contents of register $r$ into memory location addressed by $(x, y)$.
- The exact meaning of the fields depends on the addressing scheme, but the core idea is the same: register -> memory transfer.
Equations and LaTeX references
- Arithmetic operation on registers: R=A+B where A and B are values in registers, and R holds the result.
- Data movement placeholders (conceptual):
- Copy from memory to register: R
ightarrow M (or equivalently, Rext:=M) - Copy from register to memory: Mext:=R
- Architecture sizes (from the example):
- Memory cells: 256
- Registers: 16
- Conceptual fetch-decode-execute cycle: extFETCH−DECODE−EXECUTEcycle
- CPU as the brain; memory as the long-term store; registers as the short-term working memory.
- Stored-program architecture enables software-driven versatility and widespread use of general-purpose computing devices.
Quick study reminders
- Understand that opcode numbers are just encoding for specific operations (e.g., $3$ = store in this toy machine).
- Distinguish between the source register (holding data) and the destination (memory address) where data will be written.
- Remember that the actual numeric values used in an instruction refer to identifiers (register numbers or memory addresses), not the literal data values stored in those registers.