Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.

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

Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
CS 61C L13Introduction to MIPS: Instruction Representation I (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Chapter 2 Instructions: Language of the Computer Part III.
Ans: (b) Moore’s law projects the doubling of transistors every couple of years and has nothing to do with registers. The number of registers will change.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 08 MIPS Instruction Representation I Lecturer SOE Dan Garcia
CS61C L10 : MIPS Instruction Representation II (1) Pearce, Summer 2010 © UCB inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 MIPS.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
CS61C L14 Introduction to MIPS: Instruction Representation II (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 13 MIPS Instruction Representation I Shanghai Jiaotong University and Lanxiang.
CS 61C L09 Instruction Format (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #9: MIPS Instruction.
Instruction Representation III (1) Fall 2007 Lecture 11: Disassembly and Pseudo-instructions.
CS61C L14 MIPS Instruction Representation II (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
releases HotSpotAtHome
CS61C L13 MIPS Instruction Representation I (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Chap Instruction Representation Jen-Chang Liu, Spring 2006 Adapted from
CS61C L13 Introduction to MIPS: Instruction Representation I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
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.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
Instruction Representation I (1) Fall 2005 Lecture 05: INSTRUCTION REPRESENTATION.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 13 MIPS Instruction Representation I The National Science Foundation (NSF)
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L14 MIPS Instruction Representation II (1) Garcia, Fall 2006 © UCB Intel: 80 cores/chip in 5 yrs!  At their developer’s forum in SF on Tuesday,
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 14 MIPS Instruction Representation II IBM wants to use “self-assembling”
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Instructor: Justin Hsia 7/03/2013Summer Lecture #71 CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CMPE 325 Computer Architecture II
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
ECE 15B Computer Organization Spring 2011 Dmitri Strukov Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy,
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
CENG 311 Instruction Representation
EE 3755 Datapath Presented by Dr. Alexander Skavantzos.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Branch Addressing op rs rt address address beq $s1, $s2, Label if ($s1 = =$s2) go to Label 6 bits 5 bits 5 bits 16 bits effective 32 bit address.
Dan Garcia 1 CS 61C: Great Ideas in Computer Architecture MIPS Instruction Representation II.
Lecture 17: 10/31/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats 1 Instructors: Vladimir Stojanovic and Nicholas Weaver
Instruction Representation. Levels of Representation (abstractions) High Level Language Program (e.g., C) Assembly Language Program (e.g.,MIPS) Machine.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 8, EE 334.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 08 MIPS Instruction Representation I Guest Lecturer Alan Christopher
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 14 – Introduction to MIPS Instruction Representation II Lecturer PSOE.
There is one handout today at the front and back of the room!
Morgan Kaufmann Publishers
youtube.com/watch?v=hy0ptZisr70
Lecturer PSOE Dan Garcia
“Full Throttled” TA Brian Nguyen inst.eecs.berkeley.edu/~cs61c-tc
Lecture 4: MIPS Instruction Set
MIPS Instruction Encoding
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Part II Instruction-Set Architecture
Instructions and Conditional Execution
CS61C : Machine Structures Lecture 3. 1
COMS 361 Computer Organization
Lecturer SOE Dan Garcia
MIPS Coding Continued.
Presentation transcript:

Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II

Instruction Representation II (2) Fall 2007 I-Format Problems (1/3) Problem: Chances are that addi, lw, sw and slti will use immediates small enough to fit in the immediate field. …but what if it’s too big? We need a way to deal with a 32-bit immediate in any I-format instruction.

Instruction Representation II (3) Fall 2007 I-Format Problems (2/3) Solution: Handle it in software + new instruction Don’t change the current instructions: instead, add a new instruction to help out New instruction: lui register, immediate stands for Load Upper Immediate takes 16-bit immediate and puts these bits in the upper half (high order half) of the specified register sets lower half to 0s

Instruction Representation II (4) Fall 2007 I-Format Problems (3/3) Solution (continued): So how does lui help us? Example: addi $t0,$t0, 0xABABCDCD becomes: lui $at, 0xABAB ori $at, $at, 0xCDCD add $t0,$t0,$at Now each I-format instruction has only a 16- bit immediate. Wouldn’t it be nice if the assembler would do this for us automatically? (later)

Instruction Representation II (5) Fall 2007 Branches: PC-Relative Addressing (1/5) Use I-Format opcodersrtimmediate opcode specifies beq v. bne rs and rt specify registers to compare What can immediate specify? Immediate is only 16 bits PC (Program Counter) needs a 32 bit target branch address for its next fetch cycle. So immediate cannot specify entire address to branch to.

Instruction Representation II (6) Fall 2007 Branches: PC-Relative Addressing (2/5) How do we usually use branches? Answer: if-else, while, for Loops are generally small: typically up to 50 instructions Function calls and unconditional jumps are done using jump instructions ( j and jal ), not branches. Conclusion: may want to jump to anywhere in memory, but a branch often changes PC by a small amount

Instruction Representation II (7) Fall 2007 Branches: PC-Relative Addressing (3/5) Solution to branches in a 32-bit instruction: PC-Relative Addressing Let the 16-bit immediate field be a signed two’s complement integer to be added to the PC if we take the branch. Now we can branch ± 2 15 bytes from the PC, which should be enough to cover almost any loop. Any ideas to further optimize this?

Instruction Representation II (8) Fall 2007 Branches: PC-Relative Addressing (4/5) Note: Instructions are words, so they’re word aligned (byte address is always a multiple of 4, which means it ends with 00 in binary). So the number of bytes to add to the PC will always be a multiple of 4. So specify the immediate in words. Now, we can branch ± 2 15 words from the PC (or ± 2 17 bytes), so we can handle loops 4 times as large.

Instruction Representation II (9) Fall 2007 Branches: PC-Relative Addressing (5/5) Branch Calculation: If we don’t take the branch: PC = PC + 4 PC+4 = byte address of next instruction If we do take the branch: PC = (PC + 4) + ( immediate * 4) Observations -Immediate field specifies the number of words to jump, which is simply the number of instructions to jump. -Immediate field can be positive or negative. -Due to how the hardware works (PC <- PC+4 right after fetch), add immediate to (PC+4), not to PC (details later)

Instruction Representation II (10) Fall 2007 Branch Exercise (1/3) MIPS Code: Loop:beq $9,$0,End add $8,$8,$10 addi $9,$9,-1 j Loop End: Write the machine code for the beq instruction. I-Format: opcode = 4 (look up in table) rs = 9 (first operand) rt = 0 (second operand) immediate = ???

Instruction Representation II (11) Fall 2007 Branch Exercise Answer (2/3) MIPS Code: Loop:beq $9,$0,End addi $8,$8,$10 addi $9,$9,-1 j Loop End: Immediate Field: Number of instructions to add to (or subtract from) the PC, starting at the instruction following the branch. In beq case, immediate = 3

Instruction Representation II (12) Fall 2007 Branch Exercise Answer (3/3) MIPS Code: Loop:beq $9,$0,End addi $8,$8,$10 addi $9,$9,-1 j Loop End: 4903 decimal representation: binary representation:

Instruction Representation II (13) Fall 2007 Questions on PC-relative addressing Does the value in branch field change if we move the code? What do we do if destination is > 2 15 instructions away from branch?

Instruction Representation II (14) Fall 2007 Questions on PC-relative addressing Does the value in branch field change if we move the code? NO, this is a relative address What do we do if destination is > 2 15 instructions away from branch? Insert extra J instruction: BNE $s1,$s2,FAR FAR: J FARTHER FARTHER:

Instruction Representation II (15) Fall 2007 J-Format Instructions (1/5) For branches, we assumed that we won’t want to branch too far, so we can specify change in PC. For general jumps ( j and jal ), we may jump to anywhere in memory. We want to specify a 32-bit memory address to jump to. Unfortunately, we can’t fit both a 6-bit opcode and a 32-bit address into a single 32-bit word, so MIPS does the following.

Instruction Representation II (16) Fall 2007 J-Format Instructions (2/5) Define “fields” of the following number of bits each: 6 bits26 bits opcodetarget address As usual, each field has a name: Key Concepts Keep opcode field identical to R-format and I-format for consistency (6 bits). Combine all other fields to make room for large target address (26 bits).

Instruction Representation II (17) Fall 2007 J-Format Instructions (3/5) The J instruction only has room for 26 bits of the 32-bit bit address. Optimization: Like with branches, jumps will only jump to word aligned addresses, so last two bits are always 00 (in binary). So let’s just take this for granted and not even specify them in the instruction.

Instruction Representation II (18) Fall 2007 J-Format Instructions (4/5) Thus at assembly time, the machine code for a J instruction is constructed by putting 26 bits in the instruction and assuming 2 bits of 00. (total of 28 bits) Where do we get the other 4 bits? At execution time, the MIPS processor will take the 4 highest order bits from the PC and add on (whatever that 4 bit value is when it executes the J instruction). Technically, this means that we cannot jump to anywhere in memory, but it’s adequate …% of the time, since programs aren’t that long -A problem only if straddle a 256 MB boundary If we absolutely need to jump farther, we can always put it in a register and use the jr instruction.

Instruction Representation II (19) Fall 2007 J-Format Instructions (5/5) At execution time: New PC = { PC[31..28], target address, 00 } Understand where each part came from! Note: {,, } means concatenation { 4 bits, 26 bits, 2 bits } = 32 bit address { 1010, , 00 } =

Instruction Representation II (20) Fall 2007 Jump Instruction Exercise (1/4) Show the machine instruction for J DEST DEST: J Format Opcode is 0x2 DEST = 0x34F8

Instruction Representation II (21) Fall 2007 Jump Exercise Answer (2/4) J Format Opcode is 0x2 -> DEST = 0x34F8 --> binary representation: hex representation: (group by 4 bits) D 3 E

Instruction Representation II (22) Fall 2007 Jump Exercise Answer (3/4) Show the contents of the PC when this instruction is executed at runtime. This is the J DEST instruction in binary: This is the current value of the PC: Fill in the new value of the PC (with the value of DEST): HW does this when the J is executed

Instruction Representation II (23) Fall 2007 Jump Exercise Answer (4/4) Show the contents of the PC when this instruction is executed at runtime. This is the J DEST instruction in binary: This is the current value of the PC: Fill in the new value of the PC (with the value of DEST):

Instruction Representation II (24) Fall 2007 Quickie Quiz: True or False? When combining two C files into one executable, recall that they can be compiled independently & then merged together by the linker. True or False: A. Jump insts don ’ t require any changes. A. Branch insts don ’ t require any changes.

Instruction Representation II (25) Fall 2007 Quickie Quiz: True or False? When combining two C files into one executable, recall that they can be compiled independently & then merged together by the linker. True or False: Jump insts don ’ t require any changes. FALSE, the target addresses are relocatable memory addresses Branch insts don ’ t require any changes. TRUE, the target address is relative (an absolute number, not a memory address)

Instruction Representation II (26) Fall 2007 In conclusion… MIPS Machine Language Instruction: 32 bits representing a single instruction Branches use PC-relative addressing, Jumps use absolute addressing. Disassembly is simple and starts by decoding opcode field. opcodersrtimmediate opcodersrtrdfunctshamt R I J target address opcode