Lecture Overview – September 30, 2015 • Housekeeping – – – – Questions about second assignment Questions about first lab Second lab will be available by week’s end Third assignment available by Monday • Lectures and course material – Pace of the class – Questions about previous lectures • Writing code in assembler – Review of what we’ve done – Writing a few more complex programs • Glimpses at computers throughout history • Computer circuitry from logic gates to silicon • Moore’s Law A very simple computer (instruction set) Operation Operation code Stop 0 Load contents of memory location to accumulator 1 Store contents of accumulator in memory location 2 Add contents of memory location to accumulator 3 Print contents of accumulator 4 Get input from keyboard to accumulator 5 A very simple computer (architecture) CPU arithmetic, logic, control GET accumulator PRINT LOAD STORE Memory (RAM) ADD keyboard display A program to print a number A program to print a number GET get a number from keyboard into accumulator PRINT print the number that's in the accumulator STOP A program to add any two numbers GET get first number from keyboard to accumulator STORE NUM save value in RAM location labeled "NUM" GET get second number from keyboard to accumulator ADD NUM add value from NUM (1st number) to accumulator PRINT print the result (from accumulator) STOP NUM --a place to save the first number • See the code work Adding 3 numbers Read number Store at A Read number Store at B Read number Add A Add B Print result Stop A program to add any three numbers GET get first number from keyboard into accumulator STORE NUM1 save value in RAM location labeled "NUM1" GET get second number from keyboard into accumulator ADD NUM1 add value from NUM1 (1st number) to accumulator STORE NUM2 save value in RAM location labeled "NUM2" GET get third number from keyboard into accumulator ADD NUM2 add value from NUM2 (1st number) to accumulator PRINT print the result (from accumulator) STOP NUM1 --a place to save the first number NUM2 --a place to save the second number questions: how would you extend this to adding 1000 numbers? or an unknown number of numbers? Adding numbers until the number 0 is seen Read number Is It 0? No Add to Sum YES Print result Stop Operations needed for allow reuse of instructions • Have to be able to go back to a previous instruction • Have to be able to stop the repetition based on a test Instructions to allow reuse of instructions • Have to be able to go back to a previous instruction – GOTO take next instruction from a specified RAM location instead of just using next location • this lets us repeat a sequence of instructions indefinitely • Have to be able to stop the repetition based on a test – IFZERO if accumulator value is zero, go to specified location instead of using next location • these two instructions let us write programs that repeat instructions until a specified condition becomes true • the CPU can change the course of a computation according to the results of previous computations Add up a lot of numbers and print the sum Start Show Sum GET get a number from keyboard IFZERO Show if number was zero, go to "Show" ADD Sum add Sum so far to new number STORE Sum store it back in Sum so far GOTO Start go back to "Start" to get the next number LOAD Sum load sum into accumulator PRINT print result STOP 0 initial value set to 0 before program runs (by assembler) Adding a fixed number of numbers Read number Count Set Sum to 0 Set I to 1 Is I <= Count No YES Read a number and Add to Sum Add 1 to I Print Sum Stop Add up a number of numbers and print the sum Start GET STORE Count LOAD Count SUB I IFZERO Show get a number from keyboard number of numbers to add Test to see if we are done LOAD I ADD 1 STORE I Show Sum I GET get a number from keyboard ADD Sum add Sum so far to new number STORE Sum store it back in Sum so far GOTO Start go back to "Start" to get the next number LOAD Sum load sum into accumulator PRINT print result STOP 0 initial value set to 0 before program runs (by assembler) 1 initial value set to 1 before program runs (by assembler) A simulator for the toy computer • simulator (a program) reads a program written for the toy computer • simulates what the toy computer would do • toy machine's instruction repertoire: get print load Val store Lab add Val sub Val goto Lab ifpos Lab ifzero Lab stop M Num read a number from the keyboard into accumulator print contents of accumulator load accumulator with Val (which is unchanged) store contents of accumulator into location labeled Lab add Val to accumulator subtract Val from accumulator go to instruction labeled Lab go to instruction labeled Lab if accumulator positive (>= 0) go to instruction labeled Lab if accumulator is zero stop execution before program runs, set this memory location to Num if Val is a name like Sum, it refers to a memory location with that label; if Val is a number like 17, that value is used literally Scaling to real computers • Our machine had limited RAM • Word length – Each of our addresses stored 4 bytes Was a 32 bit (4 bytes x 8) machine • Accumulator – Our machine had 1 accumulator • Instruction set – We’re up to 8 instructions Scaling to real computers • Our machine had limited RAM – Current machines have 4,8,16 or more GB of memory • Word length – Each of our addresses stored 4 bytes Was a 32 bit (4 bytes x 8) machine – Current machines typically store words of 8 bytes (64 bits) 64 bit addresses are needed. Why?? • Accumulator – Our machine had 1 accumulator – Current machines have 16 (or more) accumulators (called registers) • Instruction set – We’re up to about 8 instructions – Current machines have 256 instructions, many with sub-instructions Key architectural observation • We store instructions and data together – So called Von Neumann architecture • There is a risk – Imagine reading a data address as an instruction • Looping is a very powerful construct – Beware the infinite loop • There are many benefits – Programs can modify themselves productively Pause for interesting website • The way back machine (https://archive.org/web/) – – – – – Princeton.edu Nytimes.com Dailyprincetonian.com Goprincetontigers.com …. A brief history of computing devices • Analog devices – Largely aimed at solving individual problems • Devices to win World War 2 (the first digital devices) – British machines at Bletchley Park • Post War devices – Largely done as government-industry-university collaborations in the US • The rise of personal computers Babbage – Analytical Engine (1837) Could store 1000 40 digit decimal numbers (16.7kB) Was programmable Was never built Ada Lovelace (nee Byron) the first programmer Differential analyzer (Bush and Hazen 1931) Colossus 1943 • Built to break codes • Was the first programmable (though by plugs and switches) electronic digital computer Bombe • Designed by Alan Turing starting in 1939 • Electromechanical switching • Built to emulate the German enigma machine (code breaking) IBM Automatic Sequence Controlled Calculator (ASCC) (Harvard) 1944-1959 Input/Output devices ENIAC, 1946 Size 3’x8’x100’; weight 30 tons; clock speed 5kHz; could store ~ 30 10 digit numbers Penn John von Neumann and the Johnniac (1953) Von Neumann architecture was first used on the IAS machine (1951). Johnniac had 1024 words (40 bits each) of memory. Was used 1953—66. Two paths to personal computers • Xerox Apple • Altair IBM PC Xerox PARC Alto 1973 Apple II 1977 Apple Lisa 1982 Macintosh 1984 First personal computer for sale Altair 8800 (1975) Sold for $439 as a kit, $621 assembled 4K RAM; 2 MHz clock rate Altair 8800 (1975) Programming the Altair was an extremely tedious process. The user toggled the switches to positions corresponding to an 8080 microprocessor instruction or opcode in binary, then used an 'enter' switch to load the code into the machine's memory, and then repeated this step until all the opcodes of a presumably complete and correct program were in place. When the machine first shipped the switches and lights were the only interface, and all one could do with the machine was make programs to make the lights blink. (Wikipedia) First major piece of software for Altair • BASIC programming language IBM PC 1981 http://www.dailydot.com/technology/int ernet-speed-intelligence/