1 / 18

Computer Architecture: A Constructive Approach Introduction to SMIPS Jihong Kim

Computer Architecture: A Constructive Approach Introduction to SMIPS Jihong Kim. Stored Program Concept. Instructions are bits (i.e., as numbers) Programs are stored in memory to be read or written just like data Fetch & Execute Cycle Instructions are fetched and put into a special register

ayasha
Télécharger la présentation

Computer Architecture: A Constructive Approach Introduction to SMIPS Jihong Kim

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Architecture: A Constructive ApproachIntroduction to SMIPSJihong Kim

  2. Stored Program Concept • Instructions are bits (i.e., as numbers) • Programs are stored in memory • to be read or written just like data • Fetch & Execute Cycle • Instructions are fetched and put into a special register • Bits in the register "control" the subsequent actions • Fetch the next instruction and continue Treating Instructions in the same way as Data memory for data, programs, compilers, editors, etc.

  3. Multiple Levels of Representation temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) High Level Language Program Compiler Assembly Language Program Assembler 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Machine Language Program Machine Interpretation Control Signal Specification ALUOP[0:3] <= InstReg[9:11] & MASK High and low signals on control lines

  4. SOFTWARE Instruction Set Architecture (subset of Computer Arch.) “ ... the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data flows and controls, the logical design, and the physical implementation. “ Amdahl, Blaaw, and Brooks, 1964

  5. Example ISAs • Intel 80x86 • ARM • HP PA-RISC • Sun Sparc • SGI MIPS • IBM/Motorola PowerPC

  6. MIPS I Instruction Set Architecture Registers • Instruction Categories • Load/Store • Computational • Jump and Branch • Floating Point • coprocessor • Memory Management • Special r0 - r31 PC HI LO 3 Instruction Formats: all 32 bits wide OP rs rd sa funct rt OP rs rt immediate OP jump target • SMIPS: a subset of the full MIPS32 ISA

  7. Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Execution Cycle (Conceptual Programmer’s View) Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value or status Deposit results in storage for later use Determine successor instruction

  8. MIPS Registers: Fast Locations for Data • 32 32-bit registers: $0, $1, … , $31 • operands for integer arithmetic • address calculations • temporary locations • special-purpose functions defined by convention • 1 32-bit Program Counter (PC) • 2 32-bit registers HI & LO: • used for multiply & divide • 32 32-bit registers: $f0, … $f31 • floating-point arithmetic (often used as 16 64-bit registers)

  9. MIPS Load-Store Architecture • Every operand must be in a register (a few exceptions) • Variables have to be loaded in registers. • Results have to be stored in memory. load b in register Rx load c in register Ry Rz = Rx + Ry store Rz in a Rt = Rz + Rx store Rt in d a = b + c d = a + b more variables than registers, so need explicit load and stores.

  10. MIPS arithmetic • All instructions have 3 operands • Operand order is fixed (destination first)Example: C code: A = B + C MIPS code: add $s0, $s1, $s2 C code: A = B + C + D; E = F - A; MIPS code: add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0

  11. Control Input Memory Datapath Output Processor I/O Registers vs. Memory • Arithmetic instruction’s operands must be registers: only 32 registers provided • Compiler associates variables with registers • What about programs with lots of variables? • Spilling registers • For high performance, use registers efficiently!

  12. 0 8 bits of data 1 8 bits of data 2 8 bits of data 3 8 bits of data 4 8 bits of data 5 8 bits of data 6 8 bits of data ... Memory Organization • Viewed as a large, single-dimension array, with an address. • A memory address is an index into the array • "Byte addressing" means that the index points to a byte of memory. Q: How to specify a memory location?

  13. Load & Store Instructions • Base+Offset addressing mode: offset(base register) e.g., 32($s3) • Example: • C code: A[8] = h + A[8]; • A: an array of 100 words • the base address of the array A is in $s3 • MIPS code: lw $t0, 32($s3)add $t0, $s2, $t0sw $t0, 32($s3) • Store word has destination last base register: $s3 offset: 32

  14. Example: Compiling using a Variable Array Index • C code: g = h + A[i] $s3: base register for A g, h, i: $s1, $s2, $s4 • MIPS code: add $t1, $s4, $s4 # $t1 = 2 * i add $t1, $t1, $t1 # $t1 = 4 * i add $t1, $t1, $s3 # $t1 = address of A[i] lw $t0, 0($t1) # $t0 = A[i] add $s1, $s2, $t0 # g = h + A[i]

  15. Control: bne & beq • Decision making instructions • alter the control flow, • i.e., change the "next" instruction to be executed • MIPS conditional branch instructions:bne $t0, $t1, Label beq $t0, $t1, Label • Example: if (i==j) h = i + j; bne $s0, $s1, Label add $s3, $s0, $s1 Label: ....

  16. More Branch Instructions • blezs, label if (s <= 0) gotolabel • bnezs, label if (s != 0) gotolabel

  17. Control: j • MIPS unconditional branch instructions: j label • Example:if (i!=j) beq $s4, $s5, Lab1 h=i+j; add $s3, $s4, $s5 else j Lab2 h=i-j; Lab1: sub $s3, $s4, $s5Lab2: ...

  18. A Few More ASM Instructions • slld, s, shift d = s << shift • sltd, s, j if (s < j) d = 1 else d = 0 • jrr Jump to the instruction pointed to by register r

More Related