CS107 Handout 12 Spring 2008 April 18, 2008 Computer .

2y ago
87 Views
2 Downloads
301.70 KB
5 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Laura Ramon
Transcription

CS107Handout 12Spring 2008April 18, 2008Computer Architecture: Take IHandout written by Julie Zelenski and Nick ParlanteComputer architectureA simplified picture with the major features of a computer identified. The CPU is whereall the work gets done, the memory is where all the code and data is stored. The pathconnecting the two is known as the "bus."CPUWhile memory stores the program and the data, the Central Processing Unit does all thework. The CPU has two parts— registers and an Arithmetic Logic Unit (ALU). A registeris like the temporary memory in a calculator— each register can store a value that can beused in subsequent computations. Each register can usually hold one word. Sometimesthere are separate specialized registers for holding specific types of data— floating pointnumbers, addresses, etc. The registers can be accessed much more quickly than memory,but the number of registers available is quite small compared to the size of memory. Oneof the specialized registers is the Program Counter, or PC, which holds the address ofwhich instruction is currently being executed.

2The ALU is the part of the CPU that performs the actual computations such as additionand multiplication along with comparison and other logical operations. Most modern,high-performance CPUs actually contain several specialized logic units in addition to theALU which allow them to work on several computations in parallel. However, thatcomplexity is kept (literally) within the CPU. The abstraction of the CPU is that itexecutes its instructions one at a time, in the order presented in memory.For the balance of this handout, we will concentrate on the instruction set of a typicalReduced Instruction Set Computer (RISC) processor. RISC processors are distinguishedby a relatively lean instruction set. It's turned out that you can get the best overallperformance by giving your processor a simple instruction set, and then concentratingon making the processor's instructions/second performance as high as possible. So RISCprocessors don't have some of the fancier instructions or addressing modes featured byolder Complex Instruction Set (CISC) designs. Thankfully, RISC has the added benefitthat it's easy to study since the instruction set is, well, reduced.Our fictitious processor has 32 registers, each of which can hold a 4-byte word. We willsupport three types of instructions: Load/Store instructions which move bytes back andforth between registers and memory, ALU instructions which operate on the registers,and Branch/Jump instructions that alter which instruction is executed next.LoadLoad instructions read bytes into a register. The source may be a constant value, anotherregister, or a location in memory. In our simple language, a memory location isexpressed Mem[address] where address may be a constant number, a register, or a registerplus a constant offset. Load and Store normally move a whole word at a time starting atthe given address. To move less than a whole word at a time, use thevariants “ .1” (1 byte) and “ .2” (2 bytes).Load the constant 23 into register 4R4 23Copy the contents of register 2 into register 3R3 R2Load char (one byte) starting at memory address 244 into register 6R6 .1 Mem[244]Load R5 with the word whose memory address is in R1R5 Mem[R1]Load the word that begins 8 bytes after the address in R1.This is known as "constant offset" mode and is about the fanciestaddressing mode a RISC processor will support.R4 Mem[R1 8]Just to give a sense of how this relates to the "real world", the load instruction inMotorola 68000 assembly looks like this:

3Move long (4 bytes) constant 15 to register d2movel #15, d2Move long at mem address 0x40c to register a0movel @#0x40c, a0Or in Sparc assembly, it looks like this:Load from mem address at register o0 constant offset 20 into register o1ld [ %o0 20 ], %o1The syntax of our assembly language is designed to make it easier to read and learnquickly, but the basic functionality is quite similar to any current RISC instruction set.StoreStore instructions are basically the reverse of load instructions— they move values fromregisters back out to memory. There is no path in a RISC architecture to move bytesdirectly from one place in memory to somewhere else in memory. Instead, you need touse loads to get bytes into registers, and then stores to move them back to memory.Store the constant number 37 into the word beginning at 400Mem[400] 37Store the value in R6 into the word whose address is in R1Mem[R1] R6Store lower half-word from R2 into 2 bytes starting at address 1024Mem[1024] .2 R2Store R7 into the word whose address is 12 more than the address in R1Mem[R1 12] R7ALUArithmetic Logical Unit (ALU) instructions are much like the operation keys of acalculator. ALU operations only work with the registers or constants. Some processorsdon't even allow constants (i.e. you would need to load the constant into a register first).Add 6 to R3 and store the result in R1R1 6 R3Subtract R3 from R2 and store the result in R1R1 R2 - R3Although we will use ' ' for both indiscriminately, the processor usually has twodifferent versions of the arithmetic operations, one for integers and one for floating pointnumbers, invoked by two different instructions, for example, the Sparc has add andfadd. Integer arithmetic is often much more efficient than floating point since theoperations are simpler (e.g. require no normalization). Division is by far the mostexpensive of the arithmetic operations on either type and often is not a single instruction,but a small "micro-coded" routine (think of it as very fast hand-tuned function).

4BranchingBy default, the CPU fetches and executes instructions from memory in order, workingfrom low memory to high. Branch instructions alter this default order. Branchinstructions test a condition and possibly change which instruction should be executednext by changing the value of the PC register. One condition that all processors makeheavy use of is testing whether two values are equal or if a value is less (or greater) thansome other value. The operands in the test of a branch statement must be in registers orconstant values. Branches are used to implement control structures like if and switch aswell as loops like for and while.Begin executing at address 344 if R1 equals 0BEQ R1, 0, 344"branch if equal"Begin executing at addr 8 past current instruction if R2 less than R3BLT R2, R3, PC 8"branch if less than"The full set of branch variants:BLTBLEBGTBGEBEQBNEbranch if first argument is less than secondless than or equalgreater thangreater than or equalequalnot equalAny branch instruction compares its first two arguments (which both must be registersor constants) and then potentially branches to the address given as the third argument.The destination address can be specified as an absolute address, such as 356, or a PCrelative address, such as PC-8 or PC 12. The later allows you to skip over a fewinstructions or jump to a previous instruction, which are the most common patterns forloops and conditionals.In addition, there is an unconditional jump that has no test, but just immediately divertsexecution to a new address. Like branch, the address can be specified absolute or PCrelative.Begin executing at address 2000 unconditionally- like a gotoJmp 2000Begin executing at address 12 before current instructionJmp PC-12Data conversionTwo additional instructions are utilities that convert values between integer and floatingpoint formats. Remember a floating point 1.0 has a completely different arrangement ofbits than the integer 1 and instructions are required to do those conversions. These

5instructions are also used to move values for computers that store floating point andinteger values in different sets of registers.For our purposes, we will have instructions that convert between the 4-byte integer andthe 4-byte float value. The destination and source locations for the conversion operationsmust both be registers.Take bits in R3 that represent integer, convert to float, store in R2R2 ItoF R3Take bits in R4, convert from float to int, and store back in same Notethat converting in this direction loses information, the fractionalcomponent is truncated and lostR4 FtoI R4SummaryAlthough there are a few things we bypassed (the logical and/or/not and some of theoperations that support function call/return), this simple set of instructions gives you apretty good idea of exactly what our average CPU can do in terms of instructions. Therichness and complexity of a programming language like C is provided by the compilerwhich takes something complex like a for-loop, array reference, or function call andtranslates it into an appropriate sequence of the above simple instructions.

Computer Architecture: Take I Handout written by Julie Zelenski and Nick Parlante Computer architecture A simplified picture with the major features of a computer identified. The CPU is where all the work gets done, the memory is where all the code and data is store

Related Documents:

Faculty use anecdotal notes to remember observations . Handout 2 – Sample Adequate Nursing Care Plan, pages 14-15 Handout 3 – Faculty Evaluation of Sample Nursing Care Plan, page 16 Handout 4 – Poor Concept Map, page 17 Handout 5 – Faculty Evaluation of Poor Concept Map, page 18 Handout 6 – Concept Care Map, page 19 Handout 7 – Faculty Evaluation of Good Concept Map, page 20 For .

Day 2 1. PB&J Algorithm handout 2. Algorithmic Bias handout 3. Reflection handout 4. Cats and Dogs Dataset cards 5. Playing Cards 6. Instructor Laptop and Projector 7. Student Laptops 8. Robots 9. USB Webcams Day 3 1. Ethical Matrix handouts 2. Final Project Brainstorm handout 3. Final Project Research handout 4. Reflection handout 5.

SUMMARIZING, PARAPHRASING, AND QUOTING WORKSHOP CONTENTS Lesson Plan Handout 1: "The Shanghai Secret" Handout 2: Model Citations Handout 3: A Response to "The Shanghai Secret" Handout 4: When to Use/Effective Features of Each Type of Citation Handout 5: Citations for Improvement Handout 6: "Gilmore Girls: A Girl-Power Gimmick" Reference Sheet: A Response to "The Shanghai Secret"

a) Diet b) Supplements c) Other considerations d) Clinician Handout: GERD Treatment Summary 6. IBD/IBS-D a) Diet b) Supplements c) Medications d) Patient handout: Paleo Low-FODMAP Diet e) Patient handout: GAPS Diet f) Patient Handout: How to Manage Your Stress g) Clinician Handout: IBD Remiss

Lesson 7: Identifying Skills 50 handout: Skills Identification 51 Lesson 8: things I Am Good At 53 handout: things I Am Good At 54 handout: List of 246 Skills as Verbs 55 Lesson 9: Skills Auction 56 Lesson 10: Identifying Job Values 58 handout: Job Values Inventory 60 handout: work Values Clarification 61 Lesson 11: Prioritizing Job Values 62

Lenten Journey Manual Contents Overview Handout A1: Beginning My Lenten Patterns Handout A2: Family Prayer Leader's Guide for Sessions 1, 2 and 3 Handouts for Sessions 1,2 and 3 Leader's Guide for Session 4 Handout 4a Lectio Divina Practice Handout 4b Lectio Divina Practice Handout 4c Lectio Divina Process Leader's Guide for Session 5

The Story of Monetary Policy comic book Handout 1: Prices: The Marketplace's Communication System Reading 1: Prices: The Marketplace's Communication System Handout 2: Prices in the Galaxy Handout 3: A Class Basket Handout 4: The Interest Rate Lever Handout 5: Monetary Policy Review

Am I my Brother’s Keeper? Acts 15:19-35 Introduction: Since the beginning of time when the first man and woman rebelled against God, mankind has been separated from God. Every person since that time has been born into that rebellion and sin. Because of sin, people are separated from God and are unable to have a right relationship with Him or each other. Ill. of evil and suffering Inside of .