Today in CS195: A Model of the Computer Overview: * What is a computer? Simple models * A simple language for simple computers * Write sample programs Administrivia * About this eboard. * Quiz! * Why do I give you quizzes? + To remind you that I want you to think about the things I've asked you to think about. + To give you an opportunity to show all the things you've learned + To give me information on how you're doing + To use my online quiz system + Negative side effect: Nervous students * Announcement: Meeting on Summer CS Opportunities next Thursday, 4:30 p.m. + Email me if you plan to attend. + Email me if you plan to apply for summer research. * Questions on homework 2? * Homework for Monday: Read K&R 1. * More Homework for Tuesday: Read Gries 2. * How many of you have programmed in assembly language? * Sam is a broken record: Surveys Monday -------------------------------------------------- Question: How would you arrange the Java classes for homework 2? public interface Proposition { public string toString(); } // interface Proposition public class True implements Proposition { public string toString { return "True"; } // toString } // class True /** * A representation of an implication in a simple * Boolean proposition. * * @author Samuel A. Rebelsky * @version 1.0 of January 2003. */ public class Implies implements Proposition { /** The antecendent of this implication. */ private Proposition antecedent; /** The consequent of this implication. */ private Proposition consequent; /** * Construct a new implication from two other propositions. */ public Implies(Proposition antecedent, Proposition consequent) { this.antecendent = antecendent; this.consequent = consequent; } // Implies(Proposition,Proposition) public String toString() { return "(" + this.antecedent.toString() + " => " + this.consequent.toString() + ")"; } } // class Implies When it's time to build an proposition to evaluate, ((a = b) => (not gamma)) Proposition foo = new Implies(new Equals(new Variable("alpha"), new Variable("beta")), new Not(new Variable("gamma"))); Hashtable someMapping...; someMapping.put("alpha", new True()); someMapping.put("beta", new False()); ... showEvaluationSteps(foo, someMappingOfSymbolsToTruthValues); In Scheme (showSteps '((a equals b) implies (not gamma)) ...) * Variables can be used multiple times. * No, you don't have to automatically test every assignment of variables to truth values. -------------------------------------------------- What is a computer? (In the abstract?) In the simplest model, a computer consists of * input * output * memory * central processing unit How old is this model? * About 10 seconds. Cite: D. Lindsey * The 18x0's Cite: C. Babbage Programming by Lady Ada Lovelace, Countess of When was the first working electronic computer built and by whom? * ENIAC * ABC What distinguishes a computer from other calculating devices? * Many special-purpose computing devices. * Comptuers are general purpose, they can be programmed. Key realization: The program can be store in memory Cite: John von Neumann (ca. 1950) * Alternatives include rewiring the computer for each new program Normal computer operation: * Fetch the "next" instruction (how does it know which instruction is next?) * Decodes that instruction to figure out what it says * Fetches any operands (stuff in memory) * Executes the instruction * Goes on to the next instruction A special-purpose register called the "Instruction Pointer" which stores the address of the current instruction What do the instructions look like? Labels that give mnemonics for different parts of the program Input operations (typed): iread register for "read an integer into a register" Output operations (typed): iwrite register for "write contents of this register to standard output" Computation operations: iadd register register for "add the values in the two registers, store the result in some appropriate place (usally one of the two registers, but also another register) Data movement: imove register memory-location imove memory-location register imove number register Control Jump label Jump-If-Zero register label Jump-Postive register label Jump-Negative register label Conditional jump to a label (usually involving some reasonble test) Think about how you might use these operations for three simple programs: (No quiz, but think about it) * Read two numbers, print out their sum * Read numbers until you read zero, print out their sum * Read numbers until you read zero, print them out in reverse order.