FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #6 – MIPS ISA, part 1: Instructions and Addressing.

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
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
Assembly Language II CPSC 321 Andreas Klappenecker.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
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.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Lecture 6 Sept 16 Chapter 2 continue MIPS translating c into MIPS – examples MIPS simulator (MARS and SPIM)
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Feb 18, 2009 Lecture 4-1 instruction set architecture (Part II of [Parhami]) MIPS assembly language instructions MIPS assembly programming.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #13 – Instruction Execution Steps (in a Single-Cycle.
Jan. 2011Computer Architecture, Instruction-Set ArchitectureSlide 1 Part II Instruction-Set Architecture.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #7 – MIPS ISA, part 2: Procedures and Data.
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.
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,
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
CHAPTER 6 Instruction Set Architecture 12/7/
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture & Operations I
Computer Architecture Instruction Set Architecture
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
Part II Instruction-Set Architecture
Part II Instruction-Set Architecture
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Instructions and Conditional Execution
Part IV Data Path and Control
Flow of Control -- Conditional branch instructions
3.
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Flow of Control -- Conditional branch instructions
MIPS Coding Continued.
Instruction Set Architecture
7/6/
9/13/
Presentation transcript:

FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #6 – MIPS ISA, part 1: Instructions and Addressing

2 Course Instructional Objectives #2&3  As the syllabus says: At the completion of this course, students should be able to… CIO #2 (ao). (Asm  ML) Derive machine code from assembly instructions. CIO #3 (aco). (C  Asm) Derive assembler code from an equivalent C code representation  These CIOs relate to following Program Outcomes: Students graduating from the BSEE and BSCpE degree programs will have: PO (a). (Apply) An ability to apply knowledge of mathematics, science and engineering; PO (c). (Design) An ability to design a system, component, or process to meet desired needs; PO (o). (Topics) EE: A knowledge of electrical engineering applications selected from the …digital systems… areas; CpE: A knowledge of computer science and computer engineering topics including …computer architecture.  Under “assessment instruments,” the syllabus says: 2. Asm  ML (a) Apply-3, (o) Topics-3 Students will solve exam problems in which they must hand-assemble MIPS (or similar) assembly language instructions to their binary machine-language representations. 3. C  Asm (a) Apply-3, (c) Design-3, (o) Topics-3 Students will solve exam problems in which they must hand-compile short C language code fragments to equivalent assembly language code for a MIPS or similar instruction-set architecture.

3 Detailed Objectives for CIO#2 CIO #2. Asm  ML: (ao) Derive machine code from assembly instructions. More specifically, given any assembly language instruction for a subset of the MIPS-32 instruction set (such as the MiniMIPS or MicroMIPS instructions discussed in the textbook), or a short sequence of such instructions, students should be able to hand- assemble the instructions to correct binary code, either in binary or hexadecimal format, and with all instruction fields clearly named and delineated. To accomplish this task, the student must be able to: 2.1. Identify the type (R/I/J) of a given source instruction. 2.2.Identify the name, location, and size of the bit-fields in any given instruction type (including op, rs, rt, rd, shamt, imm, jdest). 2.3.Look up the opcode (and extended opcode, if necessary) for the given instruction. 2.4.Select the appropriate bit field for encoding each instruction operand. 2.5.Convert symbolic register names to 5-bit binary codes. 2.6.Convert provided numerical constants to signed or unsigned binary formats. 2.7Resolve symbolic branch and jump destinations to the correct word offset relative to the next PC or current segment, as appropriate.

4 Detailed Objectives for CIO#3 CIO #3. C  Asm: (aco) Derive assembler code from an equivalent C code repres’n. More specifically, given any short code fragment or standalone function written in the ANSI standard C programming language, students should be able to hand-compile this source to correct working assembly language for the MIPS-32 instruction set, or a subset thereof such as MiniMIPS or MicroMIPS, while obeying standard MIPS register usage conventions. To accomplish this, students should be able to: 3.1. Identify which registers a function’s arguments can be found in, and which registers should be used to return function results Identify appropriate registers to use for storing local program variables Generate correct caller/callee code to save and restore registers using the stack in accordance with the standard MIPS calling conventions Generate correct code for accessing data stored in arrays of words Generate correct code for the evaluation of C integer arithmetic and logical expressions Translate high-level control-flow constructs including if, if/else, for, and while statements to equivalent assembly code using branch instructions Correctly use assembler directives for providing static data Correctly use pseudoinstructions for more concise and readable assembly.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 5 Part II Instruction-Set Architecture

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 6 II Instruction Set Architecture Topics in This Part Chapter 5 Instructions and Addressing Chapter 6 Procedures and Data Chapter 7 Assembly Language Programs Chapter 8 Instruction Set Variations Introduce machine “words” and its “vocabulary,” learning: A simple, yet realistic and useful instruction set Machine language programs; how they are executed RISC vs CISC instruction-set design philosophy

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 7 5 Instructions and Addressing Topics in This Chapter 5.1 Abstract View of Hardware 5.2 Instruction Formats 5.3 Simple Arithmetic / Logic Instructions 5.4 Load and Store Instructions 5.5 Jump and Branch Instructions 5.6 Addressing Modes First of two chapters on the instruction set of MiniMIPS: Required for hardware concepts in later chapters Not aiming for proficiency in assembler programming

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Abstract View of Hardware Figure 5.1 Memory and processing subsystems for MiniMIPS.  Exception PC

PCSpim appearance

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 10 Data Types MiniMIPS registers hold 32-bit (4-byte) words. Other common data sizes include byte, halfword, and doubleword. Halfword = 2 bytes Byte = 8 bits Word = 4 bytes Doubleword = 8 bytes

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 11 Register Conventions Figure 5.2 Registers and data sizes in MiniMIPS. But in SPIM, the endian-ness depends on the underlying HW

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Instruction Formats Figure 5.3 A typical instruction for MiniMIPS and steps in its execution c020

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 13 Add, Subtract, and Specification of Constants MiniMIPS add & subtract instructions; e.g., compute: g = (b + c)  (e + f) add $t8,$s2,$s3# put the sum b + c in $t8 add $t9,$s5,$s6# put the sum e + f in $t9 sub $s7,$t8,$t9# set g to ($t8)  ($t9) Decimal and hex constants Decimal 25, ,  2873 Hexadecimal 0x59, 0x12b4c6, 0xffff0000 Machine instruction typically contains an opcode one or more source operands possibly a destination operand

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 14 MiniMIPS Instruction Formats Figure 5.4 MiniMIPS instructions come in only three formats: register (R), immediate (I), and jump (J).

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Simple Arithmetic/Logic Instructions Figure 5.5 The arithmetic instructions add and sub have a format that is common to all two-operand ALU instructions. For these, the fn field specifies the arithmetic/logic operation to be performed. Add and subtract already discussed; logical instructions are similar add $t0,$s0,$s1# set $t0 to ($s0)+($s1) sub $t0,$s0,$s1# set $t0 to ($s0)-($s1) and $t0,$s0,$s1# set $t0 to ($s0)  ($s1) or $t0,$s0,$s1# set $t0 to ($s0)  ($s1) xor $t0,$s0,$s1# set $t0 to ($s0)  ($s1) nor $t0,$s0,$s1# set $t0 to (($s0)  ($s1))

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 16 Arithmetic/Logic with One Immediate Operand Figure 5.6 Instructions such as addi allow us to perform an arithmetic or logic operation for which one operand is a small constant. An operand in the range [  , ], or [ 0x0000, 0xffff ], can be specified in the immediate field. addi $t0,$s0,61# set $t0 to ($s0)+61 andi $t0,$s0,61# set $t0 to ($s0)  61 ori $t0,$s0,61# set $t0 to ($s0)  61 xori $t0,$s0,0x00ff# set $t0 to ($s0)  0x00ff For arithmetic instructions, the immediate operand is sign-extended

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Load and Store Instructions Figure 5.7 MiniMIPS lw and sw instructions and their memory addressing convention that allows for simple access to array elements via a base address and an offset (offset = 4i leads us to the ith word).

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 18 lw, sw, and lui Instructions Figure 5.8 The lui instruction allows us to load an arbitrary 16-bit value into the upper half of a register while setting its lower half to 0s. lw $t0,40($s3) # load mem[40+($s3)] in $t0 sw $t0,A($s3) # store ($t0) in mem[A+($s3)] # “ ($s3) ” means “ content of $s3 ” lui $s0,61 # The immediate value 61 is # loaded in upper half of $s0 # with lower 16b set to 0s

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 19 Initializing a Register Example 5.2 Show how each of these bit patterns can be loaded into $s0 : Solution The first bit pattern has the hex representation: 0x d lui $s0,0x2110 # put the upper half in $s0 ori $s0,0x003d# put the lower half in $s0 Same can be done, with immediate values changed to 0xffff for the second bit pattern. But, the following is simpler and faster: nor $s0,$zero,$zero # because (0  0) = 1

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Jump and Branch Instructions Unconditional jump and jump through register instructions j verify # go to mem loc named “verify” jr $ra # go to address that is in $ra; # $ra may hold a return address Figure 5.9 The jump instruction j of MiniMIPS is a J-type instruction which is shown along with how its effective target address is obtained. The jump register ( jr ) instruction is R-type, with its specified register often being $ra.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 21 Conditional Branch Instructions Figure 5.10 (part 1) Conditional branch instructions of MiniMIPS. Conditional branches use PC-relative addressing bltz $s1,L # branch on ($s1)< 0 beq $s1,$s2,L # branch on ($s1)=($s2) bne $s1,$s2,L # branch on ($s1)  ($s2)

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 22 Comparison Instructions for Conditional Branching Figure 5.10 (part 2) Comparison instructions of MiniMIPS. slt $s1,$s2,$s3# if ($s2)<($s3), set $s1 to 1 # else set $s1 to 0; # often followed by beq/bne slti $s1,$s2,61# if ($s2)<61, set $s1 to 1 # else set $s1 to 0

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 23 Examples for Conditional Branching If the branch target is too far to be reachable with a 16-bit offset (rare occurrence), the assembler automatically replaces the branch instruction beq $s0,$s1,L1 with: bne $s1,$s2,L2 # skip jump if (s1)  (s2) j L1 # goto L1 if (s1)=(s2) L2:... Forming if-then constructs; e.g., if (i == j) x = x + y bne $s1,$s2,endif # branch on i  j add $t1,$t1,$t2 # execute the “ then ” part endif:... If the condition were (i < j), we would change the first line to: slt $t0,$s1,$s2 # set $t0 to 1 if i<j beq $t0,$0,endif # branch if ($t0)=0; # i.e., i not< j or i  j

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 24 Example 5.3 Compiling if-then-else Statements Show a sequence of MiniMIPS instructions corresponding to: if (i<=j){x = x+1; z = 1;} else {y = y–1; z = 2*z} Solution Similar to the “if-then” statement, but we need instructions for the “else” part and a way of skipping the “else” part after the “then” part. slt $t0,$s2,$s1 # j<i? (inverse condition) bne $t0,$zero,else # if j<i goto else part addi $t1,$t1,1 # begin then part: x = x+1 addi $t3,$zero,1 # z = 1 j endif # skip the else part else:addi $t2,$t2,-1 # begin else part: y = y–1 add $t3,$t3,$t3 # z = z+z endif:...

June 2005Computer Architecture, Instruction-Set ArchitectureSlide Addressing Modes Figure 5.11 Schematic representation of addressing modes in MiniMIPS.

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 26 Example 5.5 Finding the Maximum Value in a List of Integers List A is stored in memory beginning at the address given in $s1. List length is given in $s2. Find the largest integer in the list and copy it into $t0. Solution Scan the list, holding the largest element identified thus far in $t0. lw $t0,0($s1)# initialize maximum to A[0] addi $t1,$zero,0# initialize index i to 0 loop:add $t1,$t1,1# increment index i by 1 beq $t1,$s2,done# if all elements examined, quit add $t2,$t1,$t1# compute 2i in $t2 add $t2,$t2,$t2# compute 4i in $t2 add $t2,$t2,$s1# form address of A[i] in $t2 lw $t3,0($t2)# load value of A[i] into $t3 slt $t4,$t0,$t3# maximum < A[i]? beq $t4,$zero,loop# if not, repeat with no change addi $t0,$t3,0# if so, A[i] is the new maximum j loop# change completed; now repeat done:...# continuation of the program

June 2005Computer Architecture, Instruction-Set ArchitectureSlide 27 The 20 MiniMIPS Instructions Covered So Far InstructionUsage Load upper immediate lui rt,imm Add add rd,rs,rt Subtract sub rd,rs,rt Set less than slt rd,rs,rt Add immediate addi rt,rs,imm Set less than immediate slti rd,rs,imm AND and rd,rs,rt OR or rd,rs,rt XOR xor rd,rs,rt NOR nor rd,rs,rt AND immediate andi rt,rs,imm OR immediate ori rt,rs,imm XOR immediate xori rt,rs,imm Load word lw rt,imm(rs) Store word sw rt,imm(rs) Jump j L Jump register jr rs Branch less than 0 bltz rs,L Branch equal beq rs,rt,L Branch not equal bne rs,rt,L Copy Control transfer Logic Arithmetic Memory access op fn Table 5.1