Skip to Content

CS 273 Introduction

High Level Programming Languages

  1. Are geared (somewhat) towards how we think, not how the computer computes.
  2. Are independent of what type of computer you are using (e.g., PC, MAC, Sun)
  3. Must be translated into how the computer computes
    1. this is done by a compiler or an interpreter
  4. But how do computers compute, and why do different types matter?

Computers


{width=“431” height=“316”}

A Computer has (essentially) three things

A Processor, or CPU (central processing unit)

  1. it performs computations that are specified by instructions

Memory (stores data and instructions)

Input and Output mechanisms, or I/O (like keyboards, monitors, printers, etc.)

These all transfer information over a bus (a collection of wires)

NOTE: this is a classical conception of a computer, called the von Neumann architecture.

Thus, you can get information in, perform some computations, and get results out

How does a CPU work?

A CPU executes basic instructions, called machine instructions, or machine code

  1. simple instructions like add, subtract, move (copy), and, or, compare

Each machine instruction is executed directly by the hardware

  1. i.e., there is circuitry specifically for that operation
  2. the instructions are, in essence, what the hardware understands

All of the machine instructions that a CPU understands are called its instruction set

Thus, what a CPU does can be understood by looking at its instruction set

This idea is called defining a CPU by its ISA, or Instruction Set Architecture

Why don't all CPUs execute the same instructions? Wouldn't that make the world easier?

Yes, it would make the world easier

But when individuals in a company want to design a CPU, they can pick whatever instructions they want to (and they usually do!)

  1. Thus, they design their own ISA, different from everyone else's

Plus, then they are the only supplier of CPU's for their own ISA, so they can sell more if alot of people start using their CPU's

  1. Like the Intel-based PC's
  2. If the market is big enough, someone else might come along, such as Cyrix or AMD, and design and build a CPU that copies the ISA of the successful CPU.
  3. The internals of the CPUs are different, but the ISA is the same!

Also, CPU's may be specialized for a certain task, like controlling a car engine, or doing graphics (yes, graphics cards have CPUs), and so will have different machine instructions.

The Fetch, Decode, Execute cycle

A CPU's life is pretty boring. Once powered up and initialized, it does the same thing over and over, as fast as it can, until it is powered down.

It's actions are known as the Fetch-Decode-Execute cycle (some people might just call it the Fetch-Execute cycle).

Over and over, the CPU does this:

  1. Fetch: Read a memory location that contains a machine instruction.
  2. Decode: Figure out which instruction was just read.
  3. Execute: Perform the computation specified by the instruction.