Points available Your marks Total 100

Similar documents
MIPS%Assembly% E155%

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

MIPS Coding Continued

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

CDA3100 Midterm Exam, Summer 2013

CS/COE1541: Introduction to Computer Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Chapter 2A Instructions: Language of the Computer

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Course Administration

Midterm. CS64 Spring Midterm Exam

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

SPIM Instruction Set

CS222: MIPS Instruction Set

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Thomas Polzer Institut für Technische Informatik

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

Topic Notes: MIPS Instruction Set Architecture

Lecture 5: Procedure Calls

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

CENG3420 Lecture 03 Review

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Instruction Set Architecture

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Assembler. Lecture 8 CS301

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

CS3350B Computer Architecture MIPS Instruction Representation

Instructions: Language of the Computer

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

CS 61c: Great Ideas in Computer Architecture

Computer Architecture

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop

Lecture 4: MIPS Instruction Set

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm


Computer Organization MIPS ISA

CS 351 Exam 2 Mon. 11/2/2015

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CS3350B Computer Architecture MIPS Introduction

Examples of branch instructions

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Mips Code Examples Peter Rounce

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

CS3350B Computer Architecture

Concocting an Instruction Set

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Computer Architecture. MIPS Instruction Set Architecture

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Reduced Instruction Set Computer (RISC)

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Chapter 2. Instruction Set Architecture (ISA)

Instructions: Language of the Computer

COMPUTER ORGANIZATION AND DESIGN

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Chapter 2: Instructions:

Reduced Instruction Set Computer (RISC)

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Computer Organization and Components

Systems Architecture I

CSSE 232 Computer Architecture I. I/O and Addressing

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

ECE/CS 552: Introduction to Computer Architecture ASSIGNMENT #1 Due Date: At the beginning of lecture, September 22 nd, 2010

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

EEC 581 Computer Architecture Lecture 1 Review MIPS

CSc 256 Midterm (green) Fall 2018

ECE 30 Introduction to Computer Engineering

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

Computer Architecture

EE 361 University of Hawaii Fall

Flow of Control -- Conditional branch instructions

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

Concocting an Instruction Set

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

MIPS Assembly Language. Today s Lecture

Transcription:

CSSE 232 Computer Architecture I Rose-Hulman Institute of Technology Computer Science and Software Engineering Department Exam 1 Solutions Name: Section: 1 2 This exam is closed book. You are allowed to use the reference card from the book. You may not use a computer, calculator, or pda during the examination, except you may use a calculator only for the last question. Write all answers on these pages use the back if necessary. Be sure to show all work and document your code. Do not use instructions that we have not covered (e.g. no mult or div but you can use sll, srl). MIPS code is judged both by its correctness and its efficiency. You may use MIPS pseudoinstructions when writing MIPS code. However, the length of your instruction sequence is judged by the actual instructions to which the sequence expands. All numbers are expressed in decimal unless specifically stated otherwise. You are encouraged to read the entire exam before beginning. Points available Your marks 1 16 2 12 3 16 4 20 5 18 6 18 Total 100 20 September 2011 Page 1

Problem 1 (16 points) Consider the following MIPS assembly code with partial machine language translation to the right. fact: addi $sp, $sp, -8 0x8 29 29-8 add $t0, $t1, $t2 0x0 9 10 8 XX 0x20 sw $ra, 4($sp) 0x2b 29 31 4 sw $a0, 0($sp) slti $t0, $a0, 1 beq $t0, $zero, L1 3 addi $v0, $zero, 1 1 addi $sp, $sp, 8 jr $ra 0x0 31 XX XX XX 0x8 L1: addi $a0, $a0, -1 jal fact 0x3 0x010 0009 lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 mul $v0, $a0, $v0 jr $ra This code is loaded into memory starting at address 0x0040 0024. (a) (10 points) Fill in the missing values in the instructions above. Give the opcode, function code and JumpAddr in hex notation, and all others in decimal. Mark a field with XX if the entry does not matter. See above. (b) (3 points) How would you change the code if the branch instruction needed to branch to address 0x004f 0000? Explain why. The target address is out of range for a branch instruction (i.e. more than 2 1 5 words away. A j or a jr instruction can be used. (c) (3 points) Convert the instruction below to a 32-bit hex number. All values are decimal except the last which is hex. op rs rt rd shamt funct 0 8 9 10 0 0x20 = 0x01095020 20 September 2011 Page 2

Problem 2 (3 x 4 points = 12 points) For each pseudo-instruction in the following table, give a minimal sequence of actual MIPS instructions to accomplish the same thing. You may need to use $at for some of the sequences. Pseudo-instruction lw $t1, A($t2) Description A is a 32-bit immediate value. Read the value from memory at address (A + contents of $t2) and store result in register $t1. lui $at, UH(A) ori $at, $at, LH(A) add $at, $at, $t2 lw $t1, 0($at) or lui $at, UH(A) add $at, $at, $t2 lw $t1, LH(A)($at) ble $t1, $t2, Label Conditionally branch to instruction at Label if value in register $t1 is less than or equal to the value in register $t2. Label is less than 2 15 words away. slt $at, $t2, $t1 beq $at, $zero, label li $t2, 0x12345678 Load 0x12345678 into register $t2. lui ori $t2, 0x1234 $t2, $t2, 0x5678 20 September 2011 Page 3

Problem 3 (16 points) The following questions examine exceptions on the MIPS processor. (a) (4 points) What actions does a MIPS processor take when an exception is encountered? Be sure to give details. Execution jumps to the exception handler (at address 0x8000 0180). The address of the instruction that caused the exception is stored in the EPC register. The cause of the exception is stored in the cause register. The exception level is set to 1. (b) (4 points) How would a systems level software developer determine what caused an exception and where it occurred? The cause is recorded in the cause register. The location of the exception is recorded in the EPC register. mfc0 and mtc0 can be used to get the value of the cause and EPC registers. (c) (4 points) Are there any restrictions or limitations that systems level software developers should be aware of while handling an exception? Explain one of these limitations. Except for $k0 and $k1, and possibly $at, all registers must be saved before they are used. In general, the stack is not available. (d) (4 points) Consider the following two chunks of of MIPS assembly code..data mask:.word 0xffff0000.text start: lw $t0, mask lw $s0, branch and $s0, $s0, $t0 ori $s0, $s0, 0xffff sw $s0, branch branch: beq $s0, $s1, BOGUS la $t0, main addi $t0, $t0, 0xffff jr $t0 Executing the code on the left above does not cause an exception (regardless of whether or not the branch is taken), while the code on the right does. Explain why? The immediate value for the branch is in words, thus any immediate value will produce a word aligned address. The register value in the jr instruction is an address in bytes. The address is not word aligned and generates a bad address in text read error. 20 September 2011 Page 4

Problem 4 (20 points) You are designing a machine with 16-bit instructions, 16-bit words, a 16- bit address space, and an undetermined number of registers. Your design includes an L-type instruction used for loading an immediate value into a register and an I-type which allows an immediate value to be used with arithmetic and logical operations. Your design should allow a 16-bit value to be loaded into a register using no more than two instructions. In answering the following questions, make the best design compromises possible. (a) (4 points) Draw the format for the L-type instruction. Be sure to label each field, any unused bits and their sizes. Reasonable answers accepted. One reasonable possibility is: op rd imm 4 4 8 (b) (4 points) Draw the format for the I-type instruction. Be sure to label each field, any unused bits and their sizes. Reasonable answers accepted. One reasonable possibility is: op rs rd imm 4 4 4 4 20 September 2011 Page 5

(c) (4 points) How many registers will your design have? Reasonable answers accepted. The design presented above has 16 registers. (d) (4 points) Describe how your instruction set architecture will load a 16-bit value into a register. Reasonable answers accepted. One possibility is to use 2 L-type instructions. The first loads the upper 8 bits into the top half of the register and the second loads the lower 8 bits into the bottom half.. (e) (4 points) The I-type instruction format is used for branch instructions. What is the range of the branch instruction? Reasonable answers accepted. The design presented above allows branches from 2 3 to + 2 3 1 words. 20 September 2011 Page 6

Problem 5 (18 points) A simple car rental calculation program is provided below. Fragments of the assembly language implementation of the program are also provided to you. You must complete the program by supplying the code required in the provided spaces. The program must strictly follow MIPS register conventions. Comments are provided to assist you in understanding the purpose and arguments of each procedure. The implementations of CalcSubtotal and CalcTax are not provided for the sake of brevity. You are not required to implement these two functions. //High-level language implementation //Main program that determines the total due. int main( ) { int numdays, dailyrate, insurancefee, totaldue;.. totaldue = CalcTotalDue(numDays, dailyrate, insurancefee);... } //Procedure to calculate the total due. int CalcTotalDue( int numdays, int dailyrate, int insurancefee ) { int subtotal, tax, total; subtotal = CalcSubtotal(numDays, dailyrate); tax = CalcTax(subtotal); total = subtotal + tax + insurancefee; } return total; Procedures CalcSubtotal and CalcTax will calculate the rental subtotal and taxes respectively. 20 September 2011 Page 7

# # Assembly language implementation of the above program. #.data # data segment of the program totaldue:.word 0 numdays:.word 3 dailyrate:.word 13 insurancefee:.word 7.text # code segment of the program # Main program that calculates the total due. The inputs are numdays, # dailyrate, and insurancefee, all are available in memory. The result # totalincurred is stored back in memory. main: la $t0, numdays # read the value of numdays lw $t0, 0($t0) # from memory la $t1, dailyrate # read the value of dailyrate lw $t1, 0($t1) # from memory la $t2, insurancefee # read the value of insurancefee lw $t2, 0($t2) # from memory move $a0, $t0 move $a1, $t1 move $a2, $t2 #optional setup stack jal CalcTotalDue # Procedure calculates total # due. Takes three parameters - # numdays, dailyrate, and # insurancefee. # Procedure returns total due. move $t0, $v0 #optional undo stack 20 September 2011 Page 8

la $t1, totaldue sw $t0, 0($t1) li $v0, 10 syscall # store the result in memory # Done - so exit # Procedure CalcTotalDue calculates total due. # Takes three parameters - numdays, dailyrate, and insurancefee. # Returns the total due. # # Calls procedure CalcSubtotal to determine the subtotal. # Saves the value of subtotal in register $s0. # # Calls procedure to CalcTax to determine the tax. # Saves the value of tax in $t0. CalcTotalDue: addi $sp, $sp, -12 sw $ra, 0($sp) sw $so, 4($sp) sw $a2, 8($sp) jal CalcSubtotal # Procedure takes 2 parameters # i.e. numdays and dailyrate # subtotal value is stored in $s0. move $a0, $v0 move $s0, $v0 jal CalcTax # Procedure takes 1 parameter i.e. # subtotal. # Procedure determines and # returns the amount of tax. # Store tax in $t0. 20 September 2011 Page 9

# Calculate the return value of # totaldue using subtotal, tax, and # insurance fee. move $t0, $v0 add $t1, $t0, $s0 lw $a2, 8($sp) add $t1, $t1, $a2 move $v0, $t1, lw $ra, 0($sp) lw $s0, 4($sp) addi $sp, $sp, 8 jr $ra # Return to main. # The implementations of CalcSubtotal and CalcTax should follow. # They are not provided for the sake of brevity. 20 September 2011 Page 10

Problem 6 (18 points) You are presented with two machines, Machine 1 and Machine 2 with clock rates of 2.33GHz and 2GHz, respectively. The instruction mixes, CPI, and clock rate are shown in the table below. Machine 1 CPI Freq Inst Cycles Floating pnt ops 7 7 7 49 Integer ops 4 40 40 160 Load/Store 5 33 33 165 Branch 3 20 20 60 Total 100 434 Machine 2 CPI Freq Inst Cycles Floating pnt ops 8 5 5 40 Integer ops 5 55 55 275 Load/Store 5 17 17 85 Branch 3 23 23 69 Total 100 469 (a) (5 points) Calculate the average CPI for the Machine 1. See calculation above. CPI = 4.34 (b) (5 points) Calculate the average CPI for the Machine 2. See calculation above. CPI = 4.69 (c) (5 points) Which machine is faster? List any assumptions. Without the number of instructions in each case the performance cannot be determined. If the number of instructions is assumed to be the same. Perf Machine1 Perf Machine2 = Exec.Time Machine1 Exec.Time Machine2 Machine 1 is 20.6% faster. = CPI Machine1 # INST Machine1 1/clkfreq Machine1 CPI Machine2 # INST Machine2 1/clkfreq Machine2 = 4.34 # INST Machine1 1/2.33 Ghz 4.69 # INST Machine1 1/2 Ghz = 0.794 20 September 2011 Page 11

(d) (3 points) Suppose the clock rate of the slower machine was increased to 3GHz and the CPI of its integer instructions were reduced by 25% would it still be slower? List any assumptions. Machine 2 CPI Freq Inst Cycles Floating pnt ops 8 5 5 40 Integer ops 3.75 55 55 206.25 Load/Store 5 17 17 85 Branch 3 23 23 69 Total 100 400.25 New CPI for Machine 2 = 4.00 Without the number of instructions in each case the performance cannot be determined. If the number of instructions is assumed to be the same. Perf Machine1 Perf Machine2 = Exec.Time Machine1 Exec.Time Machine2 Machine 2 is now 39.7% faster. = CPI Machine1 # INST Machine1 1/clkfreq Machine1 CPI Machine2 # INST Machine2 1/clkfreq Machine2 = 4.34 # INST Machine1 1/2.33 Ghz 4.00 # INST Machine1 1/3 Ghz = 1.397 20 September 2011 Page 12