Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing A Computer CPSC 120 Principles of Computer Science February 6, 2012.

Similar presentations


Presentation on theme: "Designing A Computer CPSC 120 Principles of Computer Science February 6, 2012."— Presentation transcript:

1 Designing A Computer CPSC 120 Principles of Computer Science February 6, 2012

2 Quick Overview: Generic Computer  Start with our basic adder circuit  Expand it with select circuits to include logic operations as well as binary arithmetic  Encapsulate this Arithmetic Logic Unit or ALU  Package the ALU with registers and buses to allow flow of data into and out, creating a Central Processing Unit or CPU  Add to our CPU extra registers to hold coded instructions, called programs, to control the CPU actions  Hook up various external devices to easily communicate with or direct our CPU

3 A Tiny One-Bit ALU Allowing Four operations: AND, OR, NOT, and SUM

4 Modular Design to the Rescue  We can bit-slice together many ALUs to create a 4/8/16/32/64 bit ALU  As our ALU is very fast, we need quick ways to feed it inputs, keep track of outputs  We use registers to hold our inputs and outputs from the ALU  We connect our registers and ALU using buses, or pathways of parallel wires

5 An 8-Bit ALU Doing an Addition Operation

6 A Complete CPU Diagram Notice how the results of an ALU operation can be routed back into the ALU through the general purpose registers. The instruction register controls the operation choice of the ALU and the general purpose registers.

7 How do we automate the process of selecting the next operation to be done? The key idea comes from a weaver in 19th century France. Joseph Jacquard invented a system of loom control using paper cards with patterns of holes punched in them to control the lifting of the treadles that hold the various colors of thread. A great many cards in sequence were used to create fabulous patterns not possible through human memory alone.

8 Jacquard Loom The cards are read by the mechanism at the top of the loom. Each card acts as a single instruction which controls the rise and fall of the fibers being woven by the loom. Early computer programming systems used punch cards much like this.

9 Taking Control  Our CPU has an Instruction Register to hold coded instructions for bus and ALU operations  But instructions coded directly in binary (long strings of 0/1s) are hard to understand  We write our instructions in a pseudo- Math/English programming language  A translator tool, called a compiler, converts our English-like commands into binary code  Other tools help us transfer our binary code into memory on the computer, when it can be retrieved and executed by the CPU

10 Fetch/Decode/Execute Cycle  Machine code instructions are stored in numbered memory locations, often Random Access Memory or RAM  Each instruction is fetched by the control circuitry and sent along a bus to the Instruction Register.  The instruction is then decoded to turn on the various control wires to the ALU, after loading the ALU inputs from other registers.  The ALU now executes the operation with the result sent to another register or back to RAM.  The cycle is now repeated until the program ends.

11 A Complete CPU Diagram Again Notice how the results of an ALU operation can be routed back into the ALU through the general purpose registers. The instruction register pulls its next instruction from the Program Flash memory (RAM).

12 Creating/Running A Program  Use a simple text editing system (Ex. Basic Stamp Editor under Windows) to write the PBASIC commands called source code.  Save this source code as a regular file on our disk with extension.bs2  Download this translated (compiled) program to Basic Stamp II and store it in BS II program memory locations. This is now a sequence of machine code instructions.  Basic Stamp now executes or runs these machine code instructions, one after another.

13 PBASIC Program Commands  Assign values to memory variables Example: Counter = 24 Example: Counter = 24  Arithmetic operations using memory variables Example: Average = (Starting + Ending)/2 Example: Average = (Starting + Ending)/2  Output or display memory variables Example: Debug “The average is “, Average Example: Debug “The average is “, Average  Send digital signals to other devices such as electric motors, making them move or turn Example: PULSOUT LEFT_MOTOR, 650 Example: PULSOUT LEFT_MOTOR, 650  Make decisions/take actions based on inputs Example: IF (IN1 = 0) THEN GOSUB Turn_Left Example: IF (IN1 = 0) THEN GOSUB Turn_Left

14 Programming Essentials  Programs are coded instructions we use to control the operation of some computer/CPU.  The CPU can do arithmetic, send coded output, set individual pins high/low, read input from users or devices, and make decisions based on logical operations (AND, OR, NOT, etc).  Programs are written in a specific programming language: C, C++, Java, or PBASIC in our case.  Programs must be created, edited, and stored as regular files on your computer then transferred to the target device RAM for CPU execution.  Your own PC becomes a development environment for programming.

15 Programming is Writing  Programmers must learn the vocabulary of the particular language they wish to use.  Programmers must also learn the grammar or syntax rules for how to combine vocabulary items to form syntactically correct commands.  Programmers choose an appropriate development environment with efficient tools to help in editing programs. Example, to avoid careless errors in syntax.  Programmers must also clearly understand the meaning or semantics of what each program command does when it is executed.  This means having a clear mental image of how your computer program is controlling the CPU and devices.

16 The Last Mile Can be Rough  Once our excellent program is written, we must transfer it or download to our target computer/CPU so it can be executed.  This may require file transfer to some remote computer, transfer through a connected cable, wireless, etc. Just some sordid details but still we have to cope with this!  We also need to invoke or run the program so it begins controlling the CPU.  We need to interpret the actions of the target CPU/ to determine “what our program is doing.”  We need to interpret the actions of the target CPU/device to determine “what our program is doing.”  Famous quote: “Why the hell did it do that?”  In case our program is flawed in some way, we must find the problem in our code, fix it, and again transfer our code to the target CPU.  Lather, rinse, repeat.

17 A PBASIC PROGRAM ' Robotics with the BOE-BOT - HelloBoeBotYourTurn.bs2 ' BASIC Stamp does simple math, and sends the results ' to the Debug Terminal. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG CR, "What's 7 X 11?" DEBUG CR, "The answer is: " DEBUG DEC 7 * 11 END

18 A PBASIC PROGRAM ' Robotics with the BOE-BOT - HelloBoeBotYourTurn.bs2 ' BASIC Stamp does simple math, and sends the results ' to the Debug Terminal. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG CR, "What's 7 X 11?" DEBUG CR, "The answer is: " DEBUG DEC 7 * 11 END

19 Your Turn! In the next few labs you will be learning how to program the BOE-BOT microprocessor using the PBASIC programming language. To do this, you must learn the syntax and meaning of the PBASIC instructions. The pay off here is that BOE-BOT programs can control the motors mounted on the robot base and also read sensors you build on the breadboard to detect obstacles, follow lines, etc. You can program robot behaviors!


Download ppt "Designing A Computer CPSC 120 Principles of Computer Science February 6, 2012."

Similar presentations


Ads by Google