Ch. 9: Executing Instructions
  1. Computer Instructions.
    1. While running, computers follow instructions literally.
      1. No creativity, imagination or intuition.
      2. No will; no intentions, desires, purposes or goals.
      3. No sense of humor.
      4. No “common sense”.
        1. No sense of proportion or reasonableness.
        2. No notion of context.
    2. Instructions are very small.
    3. Instructions are unambiguous.
      1. Decide if 5 is less than 6.
      2. Don't decide if grits are better than oatmeal.
      3. Computers follow clear rules; they do not exercise judgment.
    4. Fetch-execute cycle. Constantly repeats:
      1. Instruction Fetch (IF).
      2. Instruction Decode (ID).
      3. Data Fetch (DF).
      4. Instruction Execution (EX).
      5. Result Return (RR).
    Subsystems
  2. Computer Anatomy.
    1. Memory: Numbered mailboxes.
      1. Addresses.
      2. Values.
      3. Limited capacity.
    2. Arithmetic and Logic Unit.
      1. Arithmetic.
      2. Comparisons.
      3. Logical ops: And, Or, etc.
    3. Input and output.
      1. Interface devices: Display, keyboard, mouse, etc.
      2. Storage devices: Disks, etc.
    4. Control.
      1. Follows the program.
      2. Tells the others what to do.
    5. Central Processing Unit (CPU) = ALU + Control Unit.
  3. Instruction execution.
    1. Instructions are stored in memory.
    2. Control unit contains a program counter (PC) holding address of the next instruction.
    3. Instructions must be brought into the CPU for execution.
    4. ALU operates on values in registers in the CPU.
    5. Data must be moved between registers and memory.
    6. Example instruction: ADD 800, 428, 884
    7. The the instruction execution page demonstrates instruction execution.
    8. Coded on a PC:
      A1AC010000 mov eax, [428] 030574030000 add eax, [884] A320030000 mov [800], eax
  4. More is better.
    1. Traditionally, there was a single CPU to do all processing.
    2. Trend is multiple CPUs.
      1. Multiple cores: More than one CPU constructed in a single chip.
      2. Multiple CPU chips in the same motherboard.
    3. Graphics cards.
      1. A separate processor specialized to graphics tasks to let the CPU do other things.
      2. Organized as a large number of small, coordinated processors.
      3. An display image can be divided into regions, each handled one of these processors.
  5. Clock
    1. Periodically generates a pulse to make the CPU do the next thing.
    2. Clock period: Time between pulses.
    3. Clock rate.
      1. Number of periods per second.
      2. Reciprocal of the period.
      3. Units.
        1. Hertz (Hz): Cycles/second.
        2. Megahertz (MHz): Millions of cycles/second.
        3. Gigahertz (GHz): Billions of cycles/second.
    4. Traditionally, each clock is one step of the fetch-execute cycle.
    5. Newer approach is to overlap.
      1. Called pipelining.
      2. More like an assembly line.
  6. Programs.
    1. Constructed from a large number of small instructions.
    2. Each instruction is coded as a number.
    3. Example is assembly language: op arg1, arg2, arg2.
    4. High-level languages: a = a + b;
      1. Most programs.
      2. Translated using a compiler:
    5. Application programs require services from the operating system.
      1. OS is resource manager and traffic cop.
      2. Running multiple programs and keeping them apart.
      3. Memory management.
        1. Assigns parts of memory to the various programs running.
        2. When you click, load the first part of the program into memory.
        3. Loads other parts as needed.
      4. Operating devices (drivers).
      5. Creating and managing files and folders.
      6. PC Operating systems: Windows, MacOS, Linux
        Several versions of each.
      7. Other OS's: iOS, Android, ChromeOS.
    6. Programmers reuse existing code.
      1. Programs evolve.
      2. Libraries provide procedures for common operations.
  7. Memory Units. When is a thousand not a thousand?
    1. Byte: 8 bits.
    2. Each byte stores one character.
    3. Four bits: nibble.
    4. Four bytes often called a “word.”
    5. Kilobyte = 210 bytes = 1024 bytes.
    6. Megabyte = 220 bytes = 10242 bytes.
    7. Gigabyte = 230 bytes.
  8. Items Stored In Memory
    1. Each slot in memory is typically one byte. Larger items are stored in adjacent cells which are stored or fetched in groups.
    2. Integer values typically use four bytes.
    3. A typical instruction occupies four bytes.
      1. Different types of CPU use different sizes.
      2. On some types of CPU, instructions are not all the same size.
  9. Typical sizes.
    1. New PCs and laptops typically have 4 Gigabytes of memory or more. Older ones may have 1 or 2.
    2. Typical desktop hard disks are 500 Gigabytes to 2 Terabytes. Laptops on the low end of that.
    3. Trend to internal flash, especially on laptops.
      1. More expensive and smaller.
      2. Faster and lower power.
      3. Typical sizes 128 or 256 Gigabytes.
  10. Integrated Circuits.
    1. Miniaturization.
    2. Integration.
      1. Whole device created at once.
      2. Cheaper.
      3. More reliable.
    3. Manufacture: Photolithogoraphy.
      1. Photoresist is exposed to UV through a mask, leaving a shadow.
      2. Acid washes exposed photoresist, exposing the layer below. The exposed material is removed by hot gasses.
      3. Remaining resist is removed.
      4. Silicon is doped to so it can function as a transistor.
      5. Additional layers and wires are deposited.
    4. Transistors: Controlled switches.
    5. Connect transistors to compute combinations.