DOC PREVIEW
Princeton COS 126 - The TOY Machine

This preview shows page 1-2-3-20-21-22-41-42-43 out of 43 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to Computer Science • Sedgewick and Wayne • Copyright © 2007 • http://www.cs.Princeton.EDU/IntroCS5. The TOY MachineWhat is TOY?An imaginary machine similar to:Ancient computers.Today’s microprocessors.And practically everything in between !Why Study TOY?Machine language programming.•How do Java programs relate to computer?•Key to understanding Java references.•Still situations today where it is really necessary.Computer architecture.•How does it work?•How is a computer put together?TOY machine. Optimized for simplicity, not cost or performance.multimedia, computer games, embedded devices, scientific computing, MMX, AltivecInside the BoxSwitches. Input data and programs.Lights. View data.Memory.•Stores data and programs.•256 16-bit "words."•Special word for stdin / stdout.Program counter (PC).•An extra 8-bit register.•Keeps track of next instruction to be executed.Registers.•Fastest form of storage.•Scratch space during computation.•16 16-bit registers.•Register 0 is always 0.Arithmetic-logic unit (ALU). Manipulate data stored in registers.Standard input, standard output. Interact with outside world.Data and Programs Are Encoded in BinaryEach bit consists of two states:•1 or 0; true or false.•Switch is on or off; wire has high voltage or low voltage.Everything stored in a computer is a sequence of bits.•Data and programs.•Text, documents, pictures, sounds, movies, executables, …M = 7710 = 010011012 = 4D16O = 7910 = 010011112 = 4F16M = 7710 = 010011012 = 4D16Binary EncodingHow to represent integers?•Use binary encoding.•Ex: 637510 = 00011000111001112+211+27+212+26+25+22+21+20637510 =+2048 +1284096 +64 +32 +4 +2 +16375 =01311211101001501417?60908160411100312150Dec1234567Bin000000010010001101000101011001118Dec9101112131415Bin10001001101010111100110111101111Hexadecimal EncodingHow to represent integers?•Use hexadecimal encoding.•Binary code, four bits at a time.•Ex: 637510 = 00011000111001112 = 18E71601311211101001501417?6090816041110031215+22+ 7 × 1601 8 E 7+ 14 × 161+ 8 × 162637510 = 1 × 163+22+ 7+ 224+ 2048 = 4096Hex01234560Dec1234567Bin00000001001000110100010101100111 7Hex89ABCDE8Dec9101112131415Bin10001001101010111100110111101111 FMachine "Core" DumpMachine contents at a particular place and time.•Record of what program has done.•Completely determines what machine will do.0008 0005 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 00008A00 8B01 1CAB 9C02 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 000000:08:10:18:20:28:..E8:F0:F8: 0000 0000 0000 0000 0000 0000 0000 0000Main Memorypc10index of nextinstructionprogramRegisters0000R20000R30000R80000R9R00000R10000RA0000RB00000000R60000R70000RC0000RDR40000R50000RE0000RF0000variablesdataindices0/8 1/92/A1/B 3/C 4/D 5/E 6/fWhy do They Call it "Core"?http://www.columbia.edu/acis/history/core.htmlA sample program. Adds 0008 + 0005 = 000D.A Sample Program00: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 haltadd.toy10pc0000RCRA0000RB0000RegistersTOY memory(program and data)commentsProgram counterTOY code to compute 000810 + 000510A Sample ProgramProgram counter. The pc is initially 10, so the machineinterprets 8A00 as an instruction.00: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 haltadd.toy10pc0000RCRA0000RB0000Registersindex of nextinstruction to executeProgram counterLoadLoad. [opcode 8]•Loads the contents of some memory location into a register.•8A00 means load the contents of memory cell 00 into register A.addr01301211101011501407?6190806040100030205816A160016opcode dest d00: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 halt10pc0000RCRA0000RB0000Registersadd.toyProgram counterLoadLoad. [opcode 8]•Loads the contents of some memory location into a register.•8B01 means load the contents of memory cell 01 into register B.0 0 1 01 0 0 ?1 1 0 0 0 10 00816B1600: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 halt011613 12 11 1015 14 7 69 8 6 4 1 03 25addropcode dest d11pc0000RCRA0000RB0008Registersadd.toyProgram counterAddAdd. [opcode 1]•Add contents of two registers and store sum in a third.•1CAB means add the contents of registers A and B and put the result into register C.source s0 1 1 10 0 1 ?0 0 0 0 1 11 01116C16A16B16opcode dest d source t00: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 halt13 12 11 1015 14 7 69 8 6 4 1 03 2512pc0000RCRA0005RB0008Registersadd.toyProgram counterStoreStore. [opcode 9]•Stores the contents of some register into a memory cell.•9C02 means store the contents of register C into memory cell 02.addr0 1 1 11 0 0 ?0 0 0 0 1 00 00916C16opcode dest d00: 0008 801: 0005 502: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 halt021613 12 11 1015 14 7 69 8 6 4 1 03 2513pc000DRCRA0005RB0008Registersadd.toyProgram counterHaltHalt. [opcode 0]•Stop the machine.00: 0008 801: 0005 502: 000D D10: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 halt14pc000DRCRA0005RB0008Registersadd.toyProgram counterTOY code to compute 000810 + 000510Same Program, Different DataProgram. Sequence of instructions. Instruction. 10, 11, 12, 13, and 14 (executed when pc points to it). Data. 00, 01, and 02 (used and changed by instructions).00: 1CAB 733901: 1CAB 733902: 0000 010: 8A00 RA ← mem[00]11: 8B01 RB ← mem[01]12: 1CAB RC ← RA + RB13: 9C02 mem[02] ← RC14: 0000 haltadd.toy10pc0000RCRA0000RB0000RegistersdataProgram counterinstructionTOY code to compute 733910 + 733910 + 11 × 160+ 10 × 161+ 12 × 162= 1 × 163= 4096 + 3072 + 160 + 11 = 733910 1CAB16LoadLoad. [opcode 8]•Loads the contents of some memory location into a register.•8A00 means load the contents of


View Full Document

Princeton COS 126 - The TOY Machine

Download The TOY Machine
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The TOY Machine and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The TOY Machine 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?