Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE331 W02.1Irwin 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 2 Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)www.cse.psu.edu/~mji.

Similar presentations


Presentation on theme: "CSE331 W02.1Irwin 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 2 Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)www.cse.psu.edu/~mji."— Presentation transcript:

1 CSE331 W02.1Irwin 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 2 Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)www.cse.psu.edu/~mji Section 2: Krishna Narayanan Course material on ANGEL: cms.psu.edu [ adapted from D. Patterson slides ]

2 CSE331 W02.2Irwin 2007 PSU Reminder: Course Administration  Instr (Sec1): Mary Jane Irwin (mji@cse.psu.edu)mji@cse.psu.edu l 348C IST Bldg l OH’s: Tues 2:30 – 3:45pm & Wed 9:15 – 10:30am  Instr (Sec2): Krishna Narayanan (snarayan@cse.psu.edu)snarayan@cse.psu.edu l 348D IST Bldg l OH’s: Mon, Thurs 2:30 – 4:00pm  TA: Evens Jean (jean@cse.psu.edu )jean@cse.psu.edu l 360E IST Bldg l OH’s: Tues, Thurs 2:30 – 4:00pm  Web: ANGEL, cms.psu.educms.psu.edu  Lab:Accounts on CSE machines in 220 IST, Windows Lab  Texts:Computer Organization and Design: The Hardware/Software Interface, 3 rd Edition Revised Printing, Patterson and Hennessy VHDL Starter’s Guide, 2 nd Edition, Yalamanchili

3 CSE331 W02.3Irwin 2007 PSU Fall Career Days http://www.fairs.sa.psu.edu/fall/student/  Wed, Sept 19 and Thurs, Sept 20  One of the largest Career Fairs in the nation - employers who are interested in hiring engineering students for co-op/interns (Sept 19) and full-time (Sept 20) positions  If you would like to volunteer to help with set up, click on Volunteer to Help link.

4 CSE331 W02.4Irwin 2007 PSU Eta Kappa Nu Tutoring  Mondays 7-9PM in 101 EE East  Free tutoring in EE/CMP ENG core courses…  EE 210  EE 310  EE 317  EE 324  EE 330  EE 350  CSE 121/122  CSE 221  CSE 260  CSE 271/275  CSE 331  CSE 465  CSE 431  Other courses available upon request  Contact Mike Barry (msb5014@psu.edu)

5 CSE331 W02.5Irwin 2007 PSU Head’s Up  Last week’s material l Course introduction, basics of a computer system, introduction to SPIM – PH 1.1-1.3, A.9  This week’s material l Introduction to MIPS assembler, adds/loads/stores -Reading assignment - PH 2.1 through 2.4  Next week’s material l MIPS control flow operations -Reading assignment - PH 2.6 & 2.5 & A.10  Reminders l Online Quiz 1 is due Thurs, Sept. 13 (by 11:55pm) l HW 2 (another spim assignment) is due Tues, Sept 11 (by 11:55pm)

6 CSE331 W02.6Irwin 2007 PSU Marketing and management will not usually ask for a combination of features, cost, and schedule that are simultaneously realizable – count on that. They will reliably ask for the impossible. … It’s a very short step from using Moore’s Law to check your road map to using it to dictate the road map. Bob Colwell, The Pentium Chronicles

7 CSE331 W02.7Irwin 2007 PSU Review: Execute Cycle Processor Control Datapath Memory contents Reg #4 ADD contents Reg #2 results put in Reg #2 The datapath executes the instructions as directed by control 000000 00100 00010 0001000000100000 Memory stores both instructions and data Devices Input Output Network

8 CSE331 W02.8Irwin 2007 PSU Review: Processor Organization  Control needs to have circuitry to l Decide which is the next instruction and input it from memory l Decode the instruction l Issue signals that control the way information flows between datapath components l Control what operations the datapath’s functional units perform l Execute instructions - functional units (e.g., adder) and storage locations (e.g., register file) l Interconnect the functional units so that the instructions can be executed as required l Load data from and store data to memory  Datapath needs to have circuitry to Fetch DecodeExec

9 CSE331 W02.9Irwin 2007 PSU Assembly Language Instructions  The language of the machine l Want an ISA that makes it easy to build the hardware and the compiler while maximizing performance and minimizing cost  Stored program (von Neumann) concept l Instructions are stored in memory (as is the data)  Our target: the MIPS ISA l similar to other ISAs developed since the 1980's l used by Broadcom, Cisco, NEC, Nintendo, Sony, … Design goals: maximize performance, minimize cost, reduce design time (time-to-market), minimize memory space (embedded systems), minimize power consumption (mobile systems)

10 CSE331 W02.10Irwin 2007 PSU RISC - Reduced Instruction Set Computer  RISC philosophy l fixed instruction lengths l load-store instruction sets l limited number of addressing modes l limited number of operations  MIPS, Sun SPARC, HP PA-RISC, IBM PowerPC …  Instruction sets are measured by how well compilers use them as opposed to how well assembly language programmers use them  CISC (C for complex), e.g., Intel x86

11 CSE331 W02.11Irwin 2007 PSU The Four Design Principles 1. Simplicity favors regularity. 2. Smaller is faster. 3. Make the common case fast. 4. Good design demands good compromises.

12 CSE331 W02.12Irwin 2007 PSU MIPS Arithmetic Instruction  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2  Each arithmetic instruction performs only one operation  Each arithmetic instruction specifies exactly three operands destination  source1 op source2 l Operand order is fixed (the destination is specified first)  The operands are contained in the datapath’s register file ( $t0, $s1, $s2 )

13 CSE331 W02.13Irwin 2007 PSU MIPS Arithmetic Instruction  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2  Each arithmetic instruction performs only one operation  Each arithmetic instruction specifies exactly three operands destination  source1 op source2 l Operand order is fixed (the destination is specified first)  The operands are contained in the datapath’s register file ( $t0, $s1, $s2 )

14 CSE331 W02.14Irwin 2007 PSU Compiling More Complex Statements  Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d

15 CSE331 W02.15Irwin 2007 PSU Compiling More Complex Statements  Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d sub$t0, $s1, $s2 add$s0, $t0, $s3

16 CSE331 W02.16Irwin 2007 PSU MIPS Register File  Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath’s register file l Thirty-two 32-bit registers -Two read ports -One write port  Registers are l Fast -Smaller is faster & Make the common case fast l Easy for a compiler to use -e.g., (A*B) – (C*D) – (E*F) can do multiplies in any order l Improves code density -Since register are named with fewer bits than a memory location  Register addresses are indicated by using $

17 CSE331 W02.17Irwin 2007 PSU MIPS Register File  Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath’s register file l Thirty-two 32-bit registers -Two read ports -One write port Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 locations 32 5 5 5  Registers are l Fast -Smaller is faster & Make the common case fast l Easy for a compiler to use -e.g., (A*B) – (C*D) – (E*F) can do multiplies in any order l Improves code density -Since register are named with fewer bits than a memory location  Register addresses are indicated by using $ 2 5 =

18 CSE331 W02.18Irwin 2007 PSU 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function results 4$a0arguments 5$a1 6$a2 7$a3 8$t0temporary: caller saves...(callee can clobber) 15$t7 Naming Conventions for Registers 16$s0callee saves... (caller can clobber) 23$s7 24$t8 temporary (cont’d) 25$t9 26$k0reserved for OS kernel 27$k1 28$gppointer to global area 29$spstack pointer 30$fpframe pointer 31$rareturn address (Hdware)

19 CSE331 W02.19Irwin 2007 PSU Registers vs. Memory  Arithmetic instructions operands must be in registers l only thirty-two registers are provided  Compiler associates variables with registers What about programs with lots of variables? Processor Control Datapath Memory Devices Input Output Network

20 CSE331 W02.20Irwin 2007 PSU Registers vs. Memory  Arithmetic instructions operands must be in registers l only thirty-two registers are provided  Compiler associates variables with registers Processor Control Datapath Memory Devices Input Output Network What about programs with lots of variables?

21 CSE331 W02.21Irwin 2007 PSU  Memory is a large, single-dimensional array  An address acts as the index into the memory array Processor – Memory Interconnections Processor Memory 32 bits ? locations read addr/ write addr read data write data 1 101 10

22 CSE331 W02.22Irwin 2007 PSU  Memory is a large, single-dimensional array  An address acts as the index into the memory array Processor – Memory Interconnections Processor Memory 32 bits ? locations read addr/ write addr read data write data 32 2 32 Bytes (4 GB)  2 30 Words (1 GW) = 4 Bytes = 1 Word 1 101 10 0 4 8 The data stored in the memory The word address of the data

23 CSE331 W02.23Irwin 2007 PSU  MIPS has two basic data transfer instructions for accessing memory (assume $s3 holds 24 10 ) lw$t0, 4($s3) #load word from memory sw$t0, 8($s3) #store word to memory  The data transfer instruction must specify l where in memory to read from (load) or write to (store) – memory address l where in the register file to write to (load) or read from (store) – register destination (source)  The memory address is formed by summing the constant portion of the instruction and the contents of the second register Accessing Memory

24 CSE331 W02.24Irwin 2007 PSU  MIPS has two basic data transfer instructions for accessing memory (assume $s3 holds 24 10 ) lw$t0, 4($s3) #load word from memory sw$t0, 8($s3) #store word to memory  The data transfer instruction must specify l where in memory to read from (load) or write to (store) – memory address l where in the register file to write to (load) or read from (store) – register destination (source)  The memory address is formed by summing the constant portion of the instruction and the contents of the second register Accessing Memory 28 32

25 CSE331 W02.25Irwin 2007 PSU MIPS Memory Addressing  The memory address is formed by summing the constant portion of the instruction and the contents of the second (base) register lw$t0, 4($s3) #what? is loaded into $t0 sw$t0, 8($s3) #$t0 is stored where? Memory... 0 1 0 0 DataWord Address 0 4 8 12 16 20 24... 1 0 0 0... 0 0 1 0... 0 0 0 1... 1 1 0 0... 0 1 0 1... 0 1 1 0 $s3 holds 8

26 CSE331 W02.26Irwin 2007 PSU MIPS Memory Addressing  The memory address is formed by summing the constant portion of the instruction and the contents of the second (base) register lw$t0, 4($s3) #what? is loaded into $t0 sw$t0, 8($s3) #$t0 is stored where? Memory... 0 1 0 0 32 bit DataWord Address 0 4 8 12 16 20 24... 1 0 0 0... 0 0 1 0... 0 0 0 1... 1 1 0 0... 0 1 0 1... 0 1 1 0 $s3 holds 8 in location 16... 0001

27 CSE331 W02.27Irwin 2007 PSU Compiling with Loads and Stores  Assuming variable b is stored in $s2 and that the base address of array A is in $s3, what is the MIPS assembly code for the C statement A[8] = A[2] - b $s3 $s3 +4 $s3 +8 $s3 +12... A[2] A[3]... A[1] A[0]

28 CSE331 W02.28Irwin 2007 PSU Compiling with Loads and Stores  Assuming variable b is stored in $s2 and that the base address of array A is in $s3, what is the MIPS assembly code for the C statement A[8] = A[2] - b $s3 $s3 +4 $s3 +8 $s3 +12... A[2] A[3]... A[1] A[0] lw$t0, 8($s3) sub$t0, $t0, $s2 sw$t0, 32($s3)

29 CSE331 W02.29Irwin 2007 PSU Compiling with a Variable Array Index  Assuming that the base address of array A is in register $s4, and variables b, c, and i are in $s1, $s2, and $s3, respectively, what is the MIPS assembly code for the C statement c = A[i] - b add$t1, $s3, $s3#array index i is in $s3 add$t1, $t1, $t1#temp reg $t1 holds 4*i $s4 $s4 +4 $s4 +8 $s4 +12... A[2] A[3]... A[1] A[0]

30 CSE331 W02.30Irwin 2007 PSU Compiling with a Variable Array Index  Assuming that the base address of array A is in register $s4, and variables b, c, and i are in $s1, $s2, and $s3, respectively, what is the MIPS assembly code for the C statement c = A[i] - b add$t1, $s3, $s3#array index i is in $s3 add$t1, $t1, $t1#temp reg $t1 holds 4*i $s4 $s4 +4 $s4 +8 $s4 +12... A[2] A[3]... A[1] A[0] add$t1, $t1, $s4#addr of A[i] now in $t1 lw$t0, 0($t1) sub$s2, $t0, $s1

31 CSE331 W02.31Irwin 2007 PSU  Small constants are used quite frequently (50% of operands in many common programs) e.g., A = A + 5; B = B + 1; C = C - 18;  Solutions? Why not? l Put “typical constants” in memory and load them l Create hard-wired registers (like $zero) for constants like 1, 2, 4, 10, … Dealing with Constants  How do we make this work?  How do we Make the common case fast !

32 CSE331 W02.32Irwin 2007 PSU  Include constants inside arithmetic instructions l Much faster than if they have to be loaded from memory (they come in from memory with the instruction itself)  MIPS immediate instructions addi$s3, $s3, 4#$s3 = $s3 + 4 Constant (or Immediate) Operands There is no subi instruction, can you guess why not?

33 CSE331 W02.33Irwin 2007 PSU MIPS Instructions, so far CategoryInstrExampleMeaning Arithmeticaddadd $s1, $s2, $s3$s1 = $s2 + $s3 subtractsub $s1, $s2, $s3$s1 = $s2 - $s3 add immediate addi $s1, $s2, 4$s1 = $s2 + 4 Data transfer load wordlw $s1, 32($s2)$s1 = Memory($s2+32) store wordsw $s1, 32($s2)Memory($s2+32) = $s1

34 CSE331 W02.34Irwin 2007 PSU End of Lecture #3

35 CSE331 W02.35Irwin 2007 PSU In may ways, legacy code is a more difficult target for a new microarchitecture. A mountain of x86 code has accumulated since the 1970s. Designing an engine to correctly run both legacy code and modern compiled code at world-class performance levels is like designing a new jet fighter to run on anything from jet-A fuel to whale blubber and coal. Bob Colwell, The Pentium Chronicles

36 CSE331 W02.36Irwin 2007 PSU Review: MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000 0…0100 0…1000 0…1100 1…1100 Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 registers ($zero - $ra) 32 5 5 5 ALU 32 0123 7654 byte address (big Endian)  Arithmetic instructions – to/from the register file  Load/store instructions - to/from memory

37 CSE331 W02.37Irwin 2007 PSU Review: Unsigned Binary Representation HexBinaryDecimal 0x000000000…00000 0x000000010…00011 0x000000020…00102 0x000000030…00113 0x000000040…01004 0x000000050…01015 0x000000060…01106 0x000000070…01117 0x000000080…10008 0x000000090…10019 … 0xFFFFFFFC1…1100 0xFFFFFFFD1…1101 0xFFFFFFFE1…1110 0xFFFFFFFF1…1111 2 32 - 1 2 32 - 2 2 32 - 3 2 32 - 4 2 32 - 1 1 1 1... 1 1 1 1 bit 31 30 29... 3 2 1 0 bit position 2 31 2 30 2 29... 2 3 2 2 2 1 2 0 bit weight 1 0 0 0... 0 0 0 0 - 1

38 CSE331 W02.38Irwin 2007 PSU Review: Signed Binary Representation 2’sc binarydecimal 1000-8 1001-7 1010-6 1011-5 1100-4 1101-3 1110-2 1111 00000 00011 00102 00113 01004 01015 01106 01117 2 3 - 1 = -(2 3 - 1) = -2 3 = 1010 complement all the bits 1011 and add a 1 complement all the bits 0101 and add a 1 0110

39 CSE331 W02.39Irwin 2007 PSU  Instructions, like registers and words of data, are also 32 bits long Example: add $t0, $s1, $s2 registers have numbers $t0=$8,$s1=$17,$s2=$18  Instruction Format: Can you guess what the field names stand for? Machine Language - Arithmetic Instruction op rs rt rd shamt funct 000000 10001 10010 01000 00000 100000

40 CSE331 W02.40Irwin 2007 PSU  Instructions, like registers and words of data, are also 32 bits long Example: add $t0, $s1, $s2 registers have numbers $t0=$8,$s1=$17,$s2=$18  Instruction Format: Machine Language - Arithmetic Instruction op rs rt rd shamt funct 000000 10001 10010 01000 00000 100000 Can you guess what the field names stand for?

41 CSE331 W02.41Irwin 2007 PSU MIPS Instruction Fields  op  rs  rt  rd  shamt  funct op rs rt rd shamt funct 6 bits5 bits 6 bits= 32 bits

42 CSE331 W02.42Irwin 2007 PSU MIPS Instruction Fields  op  rs  rt  rd  shamt  funct op rs rt rd shamt funct 6 bits5 bits 6 bits= 32 bits opcode indicating operation to be performed address of the first register source operand address of the second register source operand the register destination address shift amoun t (for shift instructions) function code that selects the specific variant of the operation specified in the opcode field

43 CSE331 W02.43Irwin 2007 PSU  Consider the load-word and store-word instr’s l What would the regularity principle have us do? -But... Good design demands compromise  Introduce a new type of instruction format l I-type for data transfer instructions (previous format was R-type for register)  Example: lw $t0, 24($s2) Where's the compromise? Machine Language - Load Instruction op rs rt 16 bit number 23 hex 18 8 24 100011 10010 01000 0000000000011000

44 CSE331 W02.44Irwin 2007 PSU  Consider the load-word and store-word instr’s l What would the regularity principle have us do? -But... Good design demands compromise  Introduce a new type of instruction format l I-type for data transfer instructions (previous format was R-type for register)  Example: lw $t0, 24($s2) Machine Language - Load Instruction op rs rt 16 bit number 23 hex 18 8 24 100011 10010 01000 0000000000011000 Where's the compromise?

45 CSE331 W02.45Irwin 2007 PSU Memory Address Location  Example: lw $t0, 24($s2) Memory dataword address (hex) 0x00000000 0x00000004 0x00000008 0x0000000c 0xf f f f f f f f $s2 0x12004094 0x00000002 24 10 + $s2 = Note that the offset can be positive or negative

46 CSE331 W02.46Irwin 2007 PSU Memory Address Location  Example: lw $t0, 24($s2) Memory dataword address (hex) 0x00000000 0x00000004 0x00000008 0x0000000c 0xf f f f f f f f $s2 0x12004094 0x00000002 24 10 + $s2 = Note that the offset can be positive or negative... 1001 0100 +... 0001 1000... 1010 1100 = 0x120040ac $t0

47 CSE331 W02.47Irwin 2007 PSU  Example: sw $t0, 24($s2)  A 16-bit offset means access is limited to memory locations within a range of +2 13 -1 to -2 13 (~8,192) words (+2 15 -1 to -2 15 (~32,768) bytes) of the address in the base register $s2 l 2’s complement (1 sign bit + 15 magnitude bits) Machine Language - Store Instruction op rs rt 16 bit number 43 18 8 24 101011 10010 01000 0000000000011000

48 CSE331 W02.48Irwin 2007 PSU  Example: sw $t0, 24($s2)  A 16-bit offset means access is limited to memory locations within a range of +2 13 -1 to -2 13 (~8,192) words (+2 15 -1 to -2 15 (~32,768) bytes) of the address in the base register $s2 l 2’s complement (1 sign bit + 15 magnitude bits) Machine Language - Store Instruction op rs rt 16 bit number 43 18 8 24 101011 10010 01000 0000000000011000

49 CSE331 W02.49Irwin 2007 PSU  What instruction format is used for the addi ? addi$s3, $s3, 4#$s3 = $s3 + 4  Machine format: Machine Language – Immediate Instructions

50 CSE331 W02.50Irwin 2007 PSU  What instruction format is used for the addi ? addi$s3, $s3, 4#$s3 = $s3 + 4  Machine format: Machine Language – Immediate Instructions op rs rt 16 bit immediate I format 8 19 19 4  The constant is kept inside the instruction itself! l So must use the I format – Immediate format l Limits immediate values to the range +2 15 –1 to -2 15

51 CSE331 W02.51Irwin 2007 PSU Instruction Format Encoding  Can reduce the complexity with multiple formats by keeping them as similar as possible l First three fields are the same in R-type and I-type  Each format has a distinct set of values in the op field InstrFrmtoprsrtrdshamtfunctaddress add R0reg 032 ten NA sub R0reg 034 ten NA addi I8 ten reg NA constant lw I35 ten reg NA address sw I43 ten reg NA address

52 CSE331 W02.52Irwin 2007 PSU Assembling Code  Remember the assembler code we compiled last lecture for the C statement A[8] = A[2] - b lw$t0, 8($s3)#load A[2] into $t0 sub$t0, $t0, $s2#subtract b from A[2] sw$t0, 32($s3)#store result in A[8]  Assemble the MIPS object code for these three instructions (decimal is fine) lw sw sub

53 CSE331 W02.53Irwin 2007 PSU Assembling Code  Remember the assembler code we compiled last lecture for the C statement A[8] = A[2] - b lw$t0, 8($s3)#load A[2] into $t0 sub$t0, $t0, $s2#subtract b from A[2] sw$t0, 32($s3)#store result in A[8]  Assemble the MIPS object code for these three instructions (decimal is fine) 35 lw 198843 sw 198320 sub 8188034

54 CSE331 W02.54Irwin 2007 PSU Review: MIPS Instructions, so far CategoryInstrOp Code ExampleMeaning Arithmetic (R format) add0 & 32 add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 & 34 sub $s1, $s2, $s3$s1 = $s2 - $s3 Arithmetic (I format) add immediate 8addi $s1, $s2, 4$s1 = $s2 + 4 Data transfer (I format) load word35lw $s1, 100($s2)$s1 = Memory($s2+100) store word43sw $s1, 100($s2)Memory($s2+100) = $s1

55 CSE331 W02.55Irwin 2007 PSU Two Key Principles of Machine Design 1. Instructions are represented as numbers 2. Programs are stored in memory to be read or written, just like numbers  Stored-program concept l Programs can be shipped as files of binary numbers – binary compatibility l Computers can inherit ready- made software provided they are compatible with an existing ISA – leads industry to align around a small number of ISAs Accounting prg (machine code) C compiler (machine code) Payroll data Source code in C for Acct prg Memory

56 CSE331 W02.56Irwin 2007 PSU Review: MIPS R3000 ISA  Instruction Categories l Load/Store l Computational l Jump and Branch l Floating Point -coprocessor l Memory Management l Special  3 Instruction Formats: all 32 bits wide R0 - R31 PC HI LO OPrs rt rdshamtfunct OPrs rt 16 bit number OP 26 bit jump target Registers R format I format 6 bits5 bits 6 bits


Download ppt "CSE331 W02.1Irwin 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 2 Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)www.cse.psu.edu/~mji."

Similar presentations


Ads by Google