8 MIPS ISA.Pdf

8 MIPS ISA.Pdf

CSEE 3827: Fundamentals of Computer Systems Instruction Set Architectures / MIPS … and the rest of the semester Source code (software) (e.g., *.java, *.c) Compiler MIPS instruction set architecture Application executable (e.g., *.exe) Single-cycle MIPS processor Performance analysis Optimization (pipelining, caches) General purpose processor (e.g., Power PC, Pentium, MIPS) Topics in modern computer architecture (multicore, on-chip networks, etc.) (hardware) 2 A second view (IGH LEVEL SWAPINT V;= INT K LANGUAGE [INT TEMP PROGRAM TEMP V;K= IN # V;K= V;K = V;K = TEMP (high level code) ] #OMPILER !SSEMBLY SWAP LANGUAGE MULI PROGRAM ADD FOR -)03 LW LW (assembly code) SW SW JR !SSEMBLER "INARY MACHINE LANGUAGE PROGRAM FOR -)03 (machine code) 1, Ê£°ÎÊÊÊÊ Ê«À}À>ÊV«i`ÊÌÊ>ÃÃiLÞÊ>}Õ>}iÊ>`ÊÌ iÊ>ÃÃiLi`ÊÌÊL>ÀÞÊ >V iÊ >}Õ>}i°Ê !LTHOUGH THE TRANSLATION FROM HIGH LEVEL LANGUAGE TO BINARY MACHINE LANGUAGE IS SHOWN IN TWO STEPS SOME COMPILERS CUT OUT THE MIDDLEMAN AND PRODUCE BINARY MACHINE LANGUAGE DIRECTLY 4HESE LANGUAGES AND THIS PROGRAM ARE EXAMINED IN MORE DETAIL IN #HAPTER #OPYRIGHT Ú %LSEVIER )NC !LL RIGHTS RESERVED 3 Assembly Code v. Machine Code • An instruction has two forms: Assembly and Machine • Assembly: human-readable form, • e.g., add t1, s0, s2 -- says take values in registers s0 and s2, add them together, store result in register t1 • Machine: bits that actually store the instruction - that feed into the various MUXs, decoders, selector bits to produce the desired computation and/or operation: • e.g., add t1, s0, s2 is 00000010 00110010 01000000 00100000 in binary • An assembler is software that converts a text file of assembly code into a binary file of machine code • very straightforward (trivial) process: each instruction converts quite easily • One “smart” thing assembler does is permit labels for branches and jumps (discussed more later). 4 What is an ISA? • An Instruction Set Architecture, or ISA, is an interface between the hardware and the software. • An ISA consists of: • a set of operations (instructions) • data units (sized, addressing modes, etc.) • processor state (registers) • input and output control (memory operations) • execution model (program counter) 5 Why have an ISA? • An ISA provides binary compatibility across machines that share the ISA • Any machine that implements the ISA X can execute a program encoded using ISA X. • You typically see families of machines, all with the same ISA, but with different power, performance and cost characteristics. • e.g., the MIPS family: Mips 2000, 3000, 4400, 10000 6 RISC machines • RISC = Reduced Instruction Set Computer • All operations are of the form Rd Rs op Rt • MIPS (and other RISC architectures) are “load-store” architectures, meaning all operations performed only on operands in registers. (The only instructions that access memory are loads and stores) • Alternative to CISC (Complex Instruction Set Computer) where operations are significantly more complex. 7 MIPS History • MIPS is a computer family • Originated as a research project at Stanford under the direction of John Hennessy called “Microprocessor without Interlocked Pipe Stages” • Commercialized by MIPS Technologies • purchased by SGI • used in previous versions of DEC workstations • now has large share of the market in the embedded space 8 Simple View of ISA: CPU + Memory addr CPU Memory Program 1 P1 Data Register Control Program 2 File P2 Data ... Function Program n ... Unit enable Pn Data R/W • CPU breaks down into • Register file: current data being operated upon • Function Unit: combinational logic that does the computation • Control: Keeps track of current program instruction • Memory: big storage tank • program(s) to be / being executed • data (used by the above programs) • special structures (not pictured): heap, stack (discussed later) • Program memory “looked at” by CPU (actually read in) while being executed • Data is transferred to register file to be “worked on”, transferred back when done 9 What is an ISA? • An Instruction Set Architecture, or ISA, is an interface between the hardware and the software. • An ISA consists of: (for MIPS) arithmetic, logical, • a set of operations (instructions) conditional, branch, etc. • data units (sized, addressing modes, etc.) 32-bit data word • processor state (registers) 32, 32-bit registers • input and output control (memory operations) load and store • execution model (program counter) 32-bit program counter 10 Register Operands • Arithmetic instructions get their operands from registers • MIPS’ 32x32-bit register file is • used for frequently accessed data • numbered 0-31 • Registers indicated with $<id> • $t0, $t1, …, $t9 for temporary values • $s0, $s1, …, $s7 for saved values 11 Registers v. Memory • Registers are faster to access than memory • Operating on data in memory requires loads and stores • (More instructions to be executed) • Compiler should use registers for variables as much as possible • Only spill to memory for less frequently used variables • Register optimization is important for performance CSEE 3827, Fall 2009 12 Arithmetic Instructions • Addition and subtraction • Three operands: two source, one destination • add a, b, c # a gets b + c • All arithmetic operations (and many others) have this form Design principle: Regularity makes implementation simpler Simplicity enables higher performance at lower cost 13 Arithmetic Example 1 add t0, g, h # temp t0=g+h add t1, i, j # temp t1=i+j f = (g + h) - (i + j) sub f, t0, t1 # f = t0-t1 C code Compiled MIPS 14 Arithmetic Example 1 w. Registers add t0, g, h # temp t0=g+h add t1, i, j # temp t1=i+j sub f, t0, t1 # f = t0-t1 Compiled MIPS store: f in $s0, g in $s1, h in $s2, i in $s3, and j in $s4 add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s5, $t0, $t1 Compiled MIPS w. registers 15 Memory Operands • Main memory used for composite data (e.g., arrays, structures, dynamic data) • To apply arithmetic operations • Load values from memory into registers (load instruction = mem read) • Store result from registers to memory (store instruction = mem write) • Memory is byte-addressed (each address identifies an 8-bit byte) • Words (32-bits) are aligned in memory (meaning each address must be a multiple of 4) • MIPS is big-endian (i.e., most significant byte stored at least address of the word) 16 Memory Operand Example 1 g = h + A[8] C code g in $s1, h in $s2, base address of A in $s3 index = 8 requires offset of 32 (8 items x 4 bytes per word) offset base register lw $t0, 32($s3) # load word add $s1, $s2, $t0 Compiled MIPS 17 Memory Operand Example 2 A[12] = h + A[8] C code h in $s2, base address of A in $s3 index = 8 requires offset of 32 (8 items x 4 bytes per word) index = 12 requires offset of 48 (12 items x 4 bytes per word) lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word Compiled MIPS 18 Registers v. Memory • Registers are faster to access than memory • Operating on data in memory requires loads and stores • (More instructions to be executed) • Compiler should use registers for variables as much as possible • Only spill to memory for less frequently used variables • Register optimization is important for performance 19 Immediate Operands • Constant data encoded in an instruction addi $s3, $s3, 4 • No subtract immediate instruction, just use the negative constant addi $s2, $s1, -1 Design principle: make the common case fast Small constants are common Immediate operands avoid a load instruction 20 The Constant Zero • MIPS register 0 ($zero) is the constant 0 • $zero cannot be overwritten • Useful for many operations, for example, a move between two registers add $t2, $s1, $zero 21 Representing Instructions • Instructions are encoded in binary (called machine code) • MIPS instructions encoded as 32-bit instruction words • Small number of formats encoding operation code (opcode), register numbers, etc. 22 Register Numbers 0RESERVED ON .AME 2EGISTER NUMBER 5SAGE CALL ZERO 4HE CONSTANT VALUE NA VnV n 6ALUES FOR RESULTS AND EXPRESSION EVALUATION NO AnA n !RGUMENTS NO TnT n 4EMPORARIES NO SnS n 3AVED YES TnT n -ORE TEMPORARIES NO GP 'LOBAL POINTER YES SP 3TACK POINTER YES FP &RAME POINTER YES RA 2ETURN ADDRESS YES &)'52% -)03 REGISTER CONVENTIONS 2EGISTER CALLED AT IS RESERVED FOR THE ASSEMBLER SEE 3ECTION AND REGISTERS CALLED K K ARE RESERVED FOR THE OPERATING SYSTEM 4HIS INFORMATION IS ALSO FOUND IN #OLUMN OF THE -)03 2EFERENCE $ATA #ARD AT THE FRONT OF THIS BOOK #OPYRIGHT Ú %LSEVIER )NC !LL RIGHTS RESERVED 23 The big picture: How a C program is executed # PROGRAM #OMPILER !SSEMBLY LANGUAGE PROGRAM !SSEMBLER /BJECT -ACHINE LANGUAGE MODULE/BJECT ,IBRARY ROUTINE MACHINE LANGUAGE ,INKER %XECUTABLE -ACHINE LANGUAGE PROGRAM ,OADER -EMORY 1, ÊÓ°Ó£Ê ÊÌÀ>Ã>ÌÊ iÀ>ÀV ÞÊvÀÊ °Ê! HIGH LEVEL LANGUAGE PROGRAM IS lRST COMPILED INTO AN ASSEMBLY LANGUAGE PROGRAM AND THEN ASSEMBLED INTO AN OBJECT MODULE IN MACHINE LANGUAGEÊ4HE LINKER COMBINES MULTIPLE MODULES WITH LIBRARY ROUTINES TO RESOLVE ALL REFERENCES 4HE LOADER THEN PLACES THE MACHINE CODE INTO THE PROPER MEMORY LOCATIONS FOR EXECUTION BY THE PROCESSOR 4O SPEED UP THE TRANSLATION PROCESS SOME STEPS ARE SKIPPED OR COMBINED 3OME COMPILERS PRODUCE OBJECT MODULES DIRECTLY AND SOME SYSTEMS USE LINKING LOADERS THAT PERFORM THE LAST TWO STEPS 4O IDENTIFY THE TYPE OF lLE 5.)8 FOLLOWS A SUFlX CONVENTION FOR lLES # SOURCE lLES ARE NAMED XC ASSEMBLY lLES ARE XS OBJECT lLES ARE NAMED XO STATICALLY LINKED LIBRARY ROUTINES ARE XA DYNAMICALLY LINKED LIBRARY ROUTES AREÊXSO AND EXECUTABLE lLES BY DEFAULT ARE CALLED AOUT

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    66 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us