CSE331 W03.1Irwin&Li Fall 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 3 Section 1: Mary Jane Irwin (www.cse.psu.edu/~mji)www.cse.psu.edu/~mji.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
331 Week 3. 1Spring 2005 Review: MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
331 W02.1Spring 05 Announcements  HW1 is due on this Friday  Appendix A (on CD) is very helpful to HW1.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
331 W02.1Fall 2003 Announcements  HW1 is due on this Friday (Sept 12 th )  Appendix A is very helpful to HW1. Check out system calls on Page A-48. 
331 Week 3. 1Fall 2003 Head’s Up  This week’s material l MIPS control flow operations (for, while, if-the-else, …) -Reading assignment - PH 3.5  Reminders.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
The MIPS 32 Our objective is to get an appreciation with: working with a “typical” computer machine language. programming in assembly language. debuging.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
CMPT 334 Computer Organization
CS224 Fall 2011 Chap 2a Computer Organization CS224 Fall 2011 Chapter 2 a With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture slide.
CSE331 W02.1Irwin Fall 2001 PSU Computer Architecture Discussion Lecture # 2 MIPS Programming.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
1 Computer Architecture COSC 3430 Lecture 3: Instructions.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
CS Computer Architecture Spring 2006 Week 4 Paul Durand ( Course url:
CSIE30300 Computer Architecture Unit 02: MIPS ISA Review Hsin-Chou Chi [Adapted from material by and
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review.
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Digital Systems Design L02 MIPS ISA Review.1 Digital Systems Design Lecture 02: MIPS ISA Review Adapted from Mary Jane Irwin ( )
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Computer Organization Rabie A. Ramadan Lecture 3.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
MIPS Instructions Instructions: Language of the Machine
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CDA 3101 Spring 2016 Introduction to Computer Organization
CPE 232 MIPS ISA1 CPE 232 Computer Organization MIPS ISA Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin ( which.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
CSE 340 Computer Architecture Summer 2016 MIPS ISA Review.
CS35101 Computer Architecture Spring 2006 Week 2.
CS 230: Computer Organization and Assembly Language
Instructions: Language of the Computer
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
Computer Instructions
Computer Architecture
Flow of Control -- Conditional branch instructions
COMS 361 Computer Organization
COMS 361 Computer Organization
Flow of Control -- Conditional branch instructions
CS352H Computer Systems Architecture
Presentation transcript:

CSE331 W03.1Irwin&Li Fall 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 3 Section 1: Mary Jane Irwin ( Section 2: Feihui Li ( ) Course material on ANGEL: cms.psu.edu [ adapted from D. Patterson slides ]

CSE331 W03.2Irwin&Li Fall 2006 PSU

CSE331 W03.3Irwin&Li Fall 2006 PSU Review: Signed Binary Representation 2’sc binarydecimal = -( ) = -2 3 = 1010 complement all the bits 1011 and add a 1 complement all the bits 0101 and add a

CSE331 W03.4Irwin&Li Fall 2006 PSU  32-bit signed numbers (2’s complement): two = 0 ten two = + 1 ten two = + 2,147,483,646 ten two = + 2,147,483,647 ten two = – 2,147,483,648 ten two = – 2,147,483,647 ten two = – 2 ten two = – 1 ten Review: MIPS Number Representations maxint minint  Converting <32 bit values into 32 bit values copy the most significant bit (the sign bit) into the “empty” bits > > l sign extend versus zero extend MSB LSB

CSE331 W03.5Irwin&Li Fall 2006 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) ALU byte address (big Endian)  Arithmetic instructions – to/from the register file  Load/store instructions – from/to memory Fetch DecodeExec

CSE331 W03.6Irwin&Li Fall 2006 PSU Review: MIPS Instructions, so far CategoryInstrOpCodeExampleMeaning Arithmetic (R format) add0 & 20add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 & 22sub $s1, $s2, $s3$s1 = $s2 - $s3 Arithmetic (I format) add immediate 8addi $s1, $s2, 4$s1 = $s2 + 4 Data transfer (I format) load word23lw $s1, 100($s2)$s1 = Memory($s2+100) store word2bsw $s1, 100($s2)Memory($s2+100) = $s1 hex

CSE331 W03.7Irwin&Li Fall 2006 PSU  Decision making instructions l alter the control flow l i.e., change the "next" instruction to be executed  MIPS conditional branch instructions: bne $s0, $s1, Lbl #go to Lbl if $s0  $s1 beq $s0, $s1, Lbl #go to Lbl if $s0=$s1  Example: if (i==j) h = i + j; bne $s0, $s1, Lbl1 add $s3, $s0, $s1 Lbl1:... Instructions for Making Decisions

CSE331 W03.8Irwin&Li Fall 2006 PSU  Instructions: bne $s0, $s1, Lbl#go to Lbl if $s0  $s1 beq $s0, $s1, Lbl#go to Lbl if $s0=$s1  Machine Formats:  How is the branch destination address specified? Assembling Branches op rs rt 16 bit number I format ???? ????

CSE331 W03.9Irwin&Li Fall 2006 PSU Specifying Branch Destinations  Could use a “base” register and add to it the 16-bit offset l which register? -Instruction Address Register (PC = program counter) - its use is automatically implied by branch -PC gets updated (PC+4) during the fetch cycle so that it holds the address of the next instruction l limits the branch distance to to instr’s from the (instruction after the) branch -but most branches are local anyway bne $s0,$s1,Lbl1 add $s3,$s0,$s1... Lbl1:  Could specify the memory address - but that would require a 32 bit field PC 

CSE331 W03.10Irwin&Li Fall 2006 PSU Disassembling Branch Destinations  The contents of the updated PC (PC+4) is added to the 16 bit branch offset which is converted into a 32 bit value by l concatenating two low-order zeros to make it a word address and then sign-extending those 18 bits  The result is written into the PC if the branch condition is true - before the next Fetch cycle PC Add 32 offset sign-extend from the low order 16 bits of the branch instruction branch dst address ? Add 4 32

CSE331 W03.11Irwin&Li Fall 2006 PSU Offset Tradeoffs  Why not just store the word offset in the low order 16 bits? Then the two low order zeros wouldn’t have to be concatenated, it would be less confusing, …  Bu that would limit the branch distance to to instr’s from the (instruction after the) branch  And concatenating the two zero bits costs us very little in additional hardware and has no impact on the clock cycle time

CSE331 W03.12Irwin&Li Fall 2006 PSU  Assembly code bne $s0, $s1, Lbl1 add $s3, $s0, $s1 Lbl1:...  Machine Format of bne : Assembling Branches Example op rs rt 16 bit offset I format  Remember After the bne instruction is fetched, the PC is updated so that it is addressing the add instruction (PC = PC + 4). The offset (plus 2 low-order zeros) is sign-extended and added to the (updated) PC

CSE331 W03.13Irwin&Li Fall 2006 PSU  Assembly code bne $s0, $s1, Lbl1 add $s3, $s0, $s1 Lbl1:...  Machine Format of bne : Assembling Branches Example op rs rt 16 bit offset I format  Remember After the bne instruction is fetched, the PC is updated so that it is addressing the add instruction (PC = PC + 4). The offset (plus 2 low-order zeros) is sign-extended and added to the (updated) PC 0x0001

CSE331 W03.14Irwin&Li Fall 2006 PSU  MIPS also has an unconditional branch instruction or jump instruction: j Lbl#go to Lbl  Example: if (i!=j) h=i+j; else h=i-j; beq$s0, $s1, Else add$s3, $s0, $s1 jExit Else:sub$s3, $s0, $s1 Exit:... Another Instruction for Changing Flow

CSE331 W03.15Irwin&Li Fall 2006 PSU  Instruction: j Lbl#go to Lbl  Machine Format: Assembling Jumps op 26-bit address J format 2 ????  How is the jump destination address specified? l As an absolute address formed by -concatenating 00 as the 2 low-order bits to make it a word address -concatenating the upper 4 bits of the current PC (now PC+4)

CSE331 W03.16Irwin&Li Fall 2006 PSU Disassembling Jump Destinations  The low order 26 bits of the jump instr converted into a 32 bit jump destination address by l concatenating two low-order zeros to create an 28 bit (word) address and then concatenating the upper 4 bits of the current PC (now PC+4) to create a 32 bit (word) address that is put into the PC prior to the next Fetch cycle PC from the low order 26 bits of the jump instruction

CSE331 W03.17Irwin&Li Fall 2006 PSU  Assemble the MIPS machine code (in decimal is fine) for the following code sequence. Assume that the addr of the beq instr is 0x hex beq$s0, $s1, Else add$s3, $s0, $s1 jExit Else:sub$s3, $s0, $s1 Exit:... Assembling Branches and Jumps

CSE331 W03.18Irwin&Li Fall 2006 PSU  Assemble the MIPS machine code (in decimal is fine) for the following code sequence. Assume that the addr of the beq instr is 0x hex beq$s0, $s1, Else add$s3, $s0, $s1 jExit Else:sub$s3, $s0, $s1 Exit:... Assembling Branches and Jumps 0x x x20 0x x c x22 0x jmp dst = (0x0) 0x (00 2 ) = 0x

CSE331 W03.19Irwin&Li Fall 2006 PSU Branching Far Away  What if the branch destination is further away than can be captured in 16 bits?  The assembler comes to the rescue – it inserts an unconditional jump to the branch target and inverts the condition beq$s0, $s1, L1 becomes bne$s0, $s1, L2 jL1 L2:

CSE331 W03.20Irwin&Li Fall 2006 PSU Compiling While Loops  Compile the assembly code for the C while loop where i is in $s0, j is in $s1, and k is in $s2 while (i!=k) i=i+j;  Basic block – A sequence of instructions without branches (except at the end) and without branch targets (except at the beginning)

CSE331 W03.21Irwin&Li Fall 2006 PSU Compiling While Loops  Compile the assembly code for the C while loop where i is in $s0, j is in $s1, and k is in $s2 while (i!=k) i=i+j; Loop:beq$s0, $s2, Exit add$s0, $s0, $s1 jLoop Exit:...  Basic block – A sequence of instructions without branches (except at the end) and without branch targets (except at the beginning)

CSE331 W03.22Irwin&Li Fall 2006 PSU  We have beq, bne, but what about branch-if- less-than?  New instruction: slt $t0, $s0, $s1 # if $s0 < $s1 #then # $t0 = 1 #else # $t0 = 0  Machine format: 2 More Instructions for Making Decisions op rs rt rd funct = 0x2a R format

CSE331 W03.23Irwin&Li Fall 2006 PSU  Since constant operands are popular in comparisons, also have slti  New instruction: slti $t0, $s0, 10 # if $s0 < 10 #then # $t0 = 1 #else # $t0 = 0  Machine format: 2 Yet More Instructions for Making Decisions op rs rt 16 bit number a x000a I format

CSE331 W03.24Irwin&Li Fall 2006 PSU Other Branch Instructions  Can use slt, beq, bne, and the fixed value of 0 in $zero to create all relative conditions less than blt $s1, $s2, Lbl less than or equal to ble $s1, $s2, Lbl greater than bgt $s1, $s2, Lbl great than or equal to bge $s1, $s2, Lbl  As pseudo instructions they are recognized (and expanded) by the assembler  The assembler needs a reserved register ( $at ) l so there are policy of use conventions for registers

CSE331 W03.25Irwin&Li Fall 2006 PSU Other Branch Instructions  Can use slt, beq, bne, and the fixed value of 0 in $zero to create all relative conditions less than blt $s1, $s2, Lbl less than or equal to ble $s1, $s2, Lbl greater than bgt $s1, $s2, Lbl great than or equal to bge $s1, $s2, Lbl  As pseudo instructions they are recognized (and expanded) by the assembler  The assembler needs a reserved register ( $at ) l so there are policy of use conventions for registers slt $at, $s1, $s2 #$at set to 1 if bne $at, $zero, Lbl # $s1 < $s2

CSE331 W03.26Irwin&Li Fall 2006 PSU  Most higher level languages have case or switch statements allowing the code to select one of many alternatives depending on a single value  Instruction: jr $t1#go to address in $t1  Machine format: Another Instruction for Changing Flow op rs funct = 0x08 R format

CSE331 W03.27Irwin&Li Fall 2006 PSU Compiling a Case (Switch) Statement switch (k) { case 0: h=i+j; break; /*k=0*/ case 1: h=i+h; break; /*k=1*/ case 2: h=i-j; break; /*k=2*/  Assuming three sequential words in memory starting at the address in $t4 have the addresses of the labels L0, L1, and L2 and k is in $s2 add$t1, $s2, $s2#$t1 = 2*k add$t1, $t1, $t1#$t1 = 4*k add$t1, $t1, $t4#$t1 = addr of JumpT[k] lw$t0, 0($t1)#$t0 = JumpT[k] jr$t0#jump based on $t0 L0:add$s3, $s0, $s1#k=0 so h=i+j jExit L1:add$s3, $s0, $s3#k=1 so h=i+h jExit L2:sub$s3, $s0, $s1#k=2 so h=i-j Exit:... $t4  L2 L1 L0 Memory

CSE331 W03.28Irwin&Li Fall 2006 PSU Review: MIPS Instructions, so far CategoryInstrOpCdExampleMeaning Arithmetic (R & I format) add0 & 20add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 & 22sub $s1, $s2, $s3$s1 = $s2 - $s3 add immediate8addi $s1, $s2, 4$s1 = $s2 + 4 Data transfer (I format) load word23lw $s1, 100($s2)$s1 = Memory($s2+100) store word2bsw $s1, 100($s2)Memory($s2+100) = $s1 Cond. branch (I format) br on equal4beq $s1, $s2, Lif ($s1==$s2) go to L br on not equal5bne $s1, $s2, Lif ($s1 !=$s2) go to L set on less than immediate aslt $s1, $s2, 100if ($s2<100) $s1=1; else $s1=0 (R format)set on less than 0 & 2aslti $s1, $s2, $s3if ($s2<$s3) $s1=1; else $s1=0 Uncond. jump jump2j 2500go to jump register0 & 08jr $t1go to $t1

CSE331 W03.29Irwin&Li Fall 2006 PSU 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) PC ALU byte address (big Endian) Fetch PC = PC+4 DecodeExec Add 32 4 Add 32 br offset

CSE331 W03.30Irwin&Li Fall 2006 PSU End of Lecture #5

CSE331 W03.31Irwin&Li Fall 2006 PSU What constitutes project success, and what constitutes failure? The art of all engineering is compromise, trading one thing for another. Bob Colwell, The Pentium Chronicles

CSE331 W03.32Irwin&Li Fall 2006 PSU MIPS Data Types Bit: 0, 1 Bit String: sequence of bits of a particular length 4 bits is a nibble 8 bits is a byte 16 bits is a half-word 32 bits is a word 64 bits is a double-word Character: ASCII 7 bit code Decimal: digits 0-9 encoded as thru two decimal digits packed per 8 bit byte Integers: 2's complement Floating Point

CSE331 W03.33Irwin&Li Fall 2006 PSU Beyond Numbers  Most computers use 8-bit bytes to represent characters with the American Std Code for Info Interchange (ASCII)  So, we need instructions to move bytes around ASCII Char ASCII Char ASCII Char ASCII Char ASCII Char ASCII Char 133!49165A97a113q 234“50266B98b114r 335#51367C99c115s 4EOT36$52468D100d116t 537%53569E101e117u 6ACK38&54670F102f118v 739‘55771G103g119w 8bksp40(56872H104h120x 9tab41)57973I105i121y 10LF42*58:74J106j122z ;75K107k123{ 12FF44,60<76L108l124| 1547/63?79O111o127DEL

CSE331 W03.34Irwin&Li Fall 2006 PSU Byte Addresses  Since bytes (8 bits) are so useful, most ISAs support addressing individual bytes in memory  Therefore, the memory address of a word must be a multiple of 4 (alignment restriction)  Big Endian: leftmost byte is word address IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA  Little Endian:rightmost byte is word address Intel 80x86, DEC Vax, DEC Alpha (Windows NT)

CSE331 W03.35Irwin&Li Fall 2006 PSU Addressing Objects: Endianess and Alignment  Big Endian: leftmost byte is word address  Little Endian: rightmost byte is word address msblsb little endian big endian Alignment restriction: requires that objects fall on address that is multiple of their size Aligned Not Aligned

CSE331 W03.36Irwin&Li Fall 2006 PSU Addressing Objects: Endianess and Alignment  Big Endian: leftmost byte is word address  Little Endian: rightmost byte is word address msblsb little endian byte big endian byte 0 Alignment restriction: requires that objects fall on address that is multiple of their size Aligned Not Aligned

CSE331 W03.37Irwin&Li Fall 2006 PSU Loading and Storing Bytes  MIPS provides special instructions to move bytes lb$t0, 1($s3) #load byte from memory sb$t0, 6($s3) #store byte to memory  What 8 bits get loaded and stored? l load byte places the byte from memory in the rightmost 8 bits of the destination register -what happens to the other bits in the register? l store byte takes the byte from the rightmost 8 bits of a register and writes it to the byte in memory -leaving the other bytes in the memory word unchanged op rs rt 16 bit number

CSE331 W03.38Irwin&Li Fall 2006 PSU Example of Loading and Storing Bytes  Given following code sequence and memory state what is the state of the memory after executing the code? add$s3, $zero, $zero lb$t0, 1($s3) sb$t0, 6($s3) Memory 0x A 0 DataWord Address (Decimal) x F F F F F F F F 0x x x  What value is left in $t0?  What if the machine was little Endian?  What word is changed in Memory and to what?

CSE331 W03.39Irwin&Li Fall 2006 PSU Example of Loading and Storing Bytes  Given following code sequence and memory state what is the state of the memory after executing the code? add$s3, $zero, $zero lb$t0, 1($s3) sb$t0, 6($s3) Memory 0x A 0 DataWord Address (Decimal) x F F F F F F F F 0x x x $t0 = 0x mem(4) = 0xFFFF90FF mem(4) = 0xFF12FFFF  What value is left in $t0?  What if the machine was little Endian?  What word is changed in Memory and to what? $t0 = 0x

CSE331 W03.40Irwin&Li Fall 2006 PSU Loading and Storing Half Words  MIPS also provides special instructions to move half words lh$t0, 1($s3) #load half word from memory sh$t0, 6($s3) #store half word to memory  What 16 bits get loaded and stored? l load half word places the half word from memory in the rightmost 16 bits of the destination register -what happens to the other bits in the register? l store half word takes the half word from the rightmost 16 bits of the register and writes it to the half word in memory -leaving the other half word in the memory word unchanged op rs rt 16 bit number

CSE331 W03.41Irwin&Li Fall 2006 PSU Shift Operations  Need operations to pack and unpack 8-bit characters into 32-bit words  Shifts move all the bits in a word left or right sll $t2, $s0, 8#$t2 = $s0 << 8 bits srl $t2, $s0, 8#$t2 = $s0 >> 8 bits op rs rt rd shamt funct  Such shifts are called logical because they fill with zeros l Notice that a 5-bit shamt field is enough to shift a 32-bit value 2 5 – 1 or 31 bit positions x00 R format

CSE331 W03.42Irwin&Li Fall 2006 PSU More Shift Operations  An arithmetic shift ( sra ) maintain the arithmetic correctness of the shifted value (i.e., a number shifted right one bit should be ½ of its original value; a number shifted left should be 2 times its original value) sra uses the most significant bit (sign bit) as the bit shifted in sll works for arithmetic left shifts for 2’s compl. (so there is no need for a sla ) sra $t2, $s0, 8#$t2 = $s0 >> 8 bits op rs rt rd shamt funct x03 R format

CSE331 W03.43Irwin&Li Fall 2006 PSU Compiling Another While Loop  Compile the assembly code for the C while loop where i is in $s3, k is in $s5, and the base address of the array save is in $s6 while (save[i] == k) i += 1;

CSE331 W03.44Irwin&Li Fall 2006 PSU Compiling Another While Loop  Compile the assembly code for the C while loop where i is in $s3, k is in $s5, and the base address of the array save is in $s6 while (save[i] == k) i += 1; Loop:sll$t1, $s3, 2 add$t1, $t1, $s6 lw$t0, 0($t1) bne$t0, $s5, Exit addi$s3, $s3, 1 jLoop Exit:...

CSE331 W03.45Irwin&Li Fall 2006 PSU Logical Operations  There are a number of bit-wise logical operations in the MIPS ISA and $t0, $t1, $t2#$t0 = $t1 & $t2 or $t0, $t1, $t2#$t0 = $t1 | $t2 nor $t0, $t1, $t2#$t0 = not($t1 | $t2) andi $t0, $t1, 0xff00#$t0 = $t1 & ff00 ori $t0, $t1, 0xff00#$t0 = $t1 | ff00 op rs rt rd shamt funct x24 R format

CSE331 W03.46Irwin&Li Fall 2006 PSU Logical Operations in Action  Logical operations operate on individual bits of the operand. $t2 = 0… $t1 = 0… and $t0, $t1, $t2$t0 = or $t0, $t1 $t2$t0 = nor $t0, $t1, $t2$t0 =

CSE331 W03.47Irwin&Li Fall 2006 PSU Logic Operations  Logic operations operate on individual bits of the operand. $t2 = 0… $t1 = 0… and $t0, $t1, $t2$t0 = or $t0, $t1 $t2$t0 = nor $t0, $t1, $t2$t0 = 0… … …

CSE331 W03.48Irwin&Li Fall 2006 PSU  We'd also like to be able to load a 32-bit constant into a register  Must use two instructions, new "load upper immediate" instruction lui $t0, 0xaaaa  Then must get the lower order bits right, i.e., ori $t0, $t0, 0xaaaa How About Larger Constants?

CSE331 W03.49Irwin&Li Fall 2006 PSU  We'd also like to be able to load a 32-bit constant into a register  Must use two instructions, new "load upper immediate" instruction lui $t0, 0xaaaa  Then must get the lower order bits right, i.e., ori $t0, $t0, 0xaaaa How About Larger Constants? f

CSE331 W03.50Irwin&Li Fall 2006 PSU Review: MIPS Instructions, so far CategoryInstrOpCExampleMeaning Arithmetic (R & I format) add0 & 20add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 & 22sub $s1, $s2, $s3$s1 = $s2 - $s3 add immediate8addi $s1, $s2, 4$s1 = $s2 + 4 shift left logical0 & 00sll $s1, $s2, 4$s1 = $s2 << 4 shift right logical 0 & 02srl $s1, $s2, 4$s1 = $s2 >> 4 (fill with zeros) shift right arithmetic 0 & 03sra $s1, $s2, 4$s1 = $s2 >> 4 (fill with sign bit) and0 & 24and $s1, $s2, $s3$s1 = $s2 & $s3 or0 & 25or $s1, $s2, $s3$s1 = $s2 | $s3 nor0 & 27nor $s1, $s2, $s3$s1 = not ($s2 | $s3) and immediatecand $s1, $s2, ff00$s1 = $s2 & 0xff00 or immediatedor $s1, $s2, ff00$s1 = $s2 | 0xff00 load upper immediate flui $s1, 0xffff$s1 = 0xffff0000

CSE331 W03.51Irwin&Li Fall 2006 PSU Review: MIPS Instructions, so far CategoryInstrOpCExampleMeaning Data transfer (I format) load word23lw $s1, 100($s2)$s1 = Memory($s2+100) store word2bsw $s1, 100($s2)Memory($s2+100) = $s1 load byte20lb $s1, 101($s2)$s1 = Memory($s2+101) store byte28sb $s1, 101($s2)Memory($s2+101) = $s1 load half21lh $s1, 101($s2)$s1 = Memory($s2+102) store half29sh $s1, 101($s2)Memory($s2+102) = $s1 Cond. branch (I & R format) br on equal4beq $s1, $s2, Lif ($s1==$s2) go to L br on not equal5bne $s1, $s2, Lif ($s1 !=$s2) go to L set on less than immediate aslti $s1, $s2, 100if ($s2<100) $s1=1; else $s1=0 set on less than 0 & 2aslt $s1, $s2, $s3if ($s2<$s3) $s1=1; else $s1=0 Uncond. jump jump2j 2500go to jump register0 & 08jr $t1go to $t1

CSE331 W03.52Irwin&Li Fall 2006 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 J format