Midterm. CS64 Spring Midterm Exam

Similar documents
MIPS%Assembly% E155%

Mips Code Examples Peter Rounce

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

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

Computer Architecture I Midterm I

Examples of branch instructions

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

Flow of Control -- Conditional branch instructions

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

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

MIPS Instruction Reference

CS61c MIDTERM EXAM: 3/17/99

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

Lecture 5: Procedure Calls

F. Appendix 6 MIPS Instruction Reference

MIPS Instruction Format

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

Q1: /30 Q2: /25 Q3: /45. Total: /100

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

SPIM Instruction Set

Computer Architecture. The Language of the Machine

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

Unsigned Binary Integers

Unsigned Binary Integers

CSc 256 Midterm (green) Fall 2018

Lecture 6 Decision + Shift + I/O

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

CS3350B Computer Architecture MIPS Instruction Representation

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

Department of Electrical Engineering and Computer Science Spring 2004 Instructor: Dan Garcia CS61C Midterm

CPS311 - COMPUTER ORGANIZATION. A bit of history

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

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

The MIPS Instruction Set Architecture

MIPS Reference Guide

UCB CS61C : Machine Structures

Lecture 4: MIPS Instruction Set

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Week 10: Assembly Programming

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

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

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

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

MIPS PROJECT INSTRUCTION SET and FORMAT

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

CSc 256 Midterm 2 Fall 2011

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

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 )

CSc 256 Midterm 2 Spring 2012

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

Chapter 2. Instructions:

ECE 30 Introduction to Computer Engineering

Computer Architecture

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

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

CS61C : Machine Structures

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

Assembly Programming

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

Computer Architecture. MIPS Instruction Set Architecture

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

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

CS3350B Computer Architecture Quiz 3 March 15, 2018

Reduced Instruction Set Computer (RISC)

Course Administration

Chapter 2A Instructions: Language of the Computer

CS61C : Machine Structures

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

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

ECE Exam I February 19 th, :00 pm 4:25pm

TSK3000A - Generic Instructions

Reduced Instruction Set Computer (RISC)

bits 5..0 the sub-function of opcode 0, 32 for the add instruction

CS3350B Computer Architecture MIPS Introduction

Computer Architecture Experiment

Points available Your marks Total 100

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

CS 61c: Great Ideas in Computer Architecture

Department of Electrical Engineering and Computer Sciences Spring 2010 Instructor: Dr. Dan Garcia CS61C Midterm

University of California, Berkeley College of Engineering

MIPS Assembly Programming

Midterm. Sticker winners: if you got >= 50 / 67

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

CDA3100 Midterm Exam, Summer 2013

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

Computer Architecture

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

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

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

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

Department of Electrical Engineering and Computer Sciences Spring 2007 Instructor: Dr. Dan Garcia

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

And in Review. Register Conventions (2/4) saved. Register Conventions (1/4) Register Conventions (4/4) Register Conventions (3/4) volatile

Lecture 9: Disassembly

Transcription:

Midterm LAST NAME FIRST NAME PERM Number Instructions Please turn off all pagers, cell phones and beepers. Remove all hats & headphones. Place your backpacks, laptops and jackets at the front. Sit in every other seat. Nothing may be placed in the no fly zone spare seat/desk between students. You have 75 minutes to complete this exam. This exam is closed book, closed notes, no computers, PDAs or calculators. WRITE YOUR NAME on EACH PAGE OF THIS TEST. You will be deducted -1 points you can not finish this task. n 2 n n 2 n 1 2 17 131072 2 4 18 262144 3 8 19 524288 4 16 20 1048576 5 32 21 2097152 6 64 22 4194304 7 128 23 8388608 8 256 24 16777216 9 512 25 33554432 10 1024 26 67108864 11 2048 27 134217728 12 4096 28 268435456 13 8192 29 536870912 14 16384 30 1073741824 15 32768 31 2147483648 16 65536 32 4294967296

Important please note: The MIPS instructions shown in this table are the ones that you must use on the entire exam. Do not use any instructions that are not in this table. If you use any instructions not listed below, you will lose points. Name Syntax Meaning add add rd, rs, rt rd=rs+rt sub sub rd, rs, rt rd=rs-rt and and rd, rs, rt rd=rs AND rt or or rd, rs, rt rd=rs OR rt sll sll rd, rt, shamt rd=logic shift rt left shamt bits srl srl rd, rt, shamt rd=logic shift rt right shamt bits sra sra rd, rt, shamt rd=arithmetic shift rt right shamt bits slt slt rd, rs, rt If rs<rt, rd=1, else rd=0 slti slti rd, rs, imm If rs<imm, rd=1, else rd=0 jr jr rs jump to the instruction held by the memory location indicated by rs addi addi rt, rs, imm rt=rs+imm andi andi rt, rs, imm rt=rs AND imm ori ori rt, rs, imm rt=rs OR imm lw lw rt, imm(rd) rt=memory[rd+imm] sw sw rt, imm(rd) MEMORY[rd+imm]=rt beq beq rs, rt, label Branch if rs==rt bne bne rs, rt, label Branch if rs!= rt j j label Jump to label jal jal label Jump to label and link

1. [5pt] Big Ideas We ve discussed two design principles that guide the authors of instruction sets (and played a part in MIPS design). Choose the corresponding item from below and map it to the right design principle (one answer per principle) Design Principle Simple is faster Smaller is faster How was the MIPS design affected a c a) Each MIPS native instruction performs one function and requires one cycle to run b) Each MIPS native instruction requires multiple cycles to run c) MIPS has 32 registers, rather than many more d) MIPS instructions only work with hexadecimal numbers 2. [5pt] Number representation, assuming a 8-bit system Consider the following bit pattern 11111111 What is the (decimal) value of this bit pattern assuming that it is in two s complement format a) 0 b) -255 c) 255 d) -1 e) Can t tell since this representation has the property of a dirty zero d 3. [15pt] Write the value of each of these binary integer numbers in DECIMAL (assuming 8-bit system) (in sign magnitude format) 10000000 0 (in one s complement format) 10000000-127 (in two s complement format) 10000000-128

(in one s complement format) 10000001-126 (in two s complement format) 10000001-127 4. [5pt] Number representation, assuming a 32-bit system What is the smallest two s complement format number that can be stored in one 32- bit word? Express your answer in both decimal (base 10) and hex (base 16) format. -2^31 0x80000000 5. [20pt] MIPS Arithmetic and Logic Instructions Assume that Register $a0 contains 0x00000FFF Register $a1 contains 0x10001011 Register $a2 contains 0x00FFFFFF at the beginning of each of the following instructions. For each instruction, give the contents of the destination register in hex format a) and $s0, $a0, $a1 0x00000011 b) add $s1, $a0, $a1 0x10002010 c) addi $s2, $a1, 0xFFFF 0x10001010 (note: oxffff is sign extended to oxffffffff) d) or $s3, $a1, $a2 0x10FFFFFF

6. [20pt] Assembly Programming Decoding Assembly Code: The following piece of MIPS code tries to reverse the contents of an array of words (base address of the array in register $a0, length of the array in register $a1). Fill in the blanks. reverse: add $t0, $zero, $a0 add $t1, $zero, $a1 addi $t1, $t1, -1 # t1 = a1-1 sll $t1, $t1, _2 # Now t1= t1 x 4 add $t1, $a0, $t1 # $t1 points to the end of the array loop: lw $t2, 0($t0) # First element of array pointed to by $t0 lw $t3, 0($t1) # Last element of the array pointed to by $t1 sw _$t2, 0($t1) sw _$t3, 0($t0) # Loads first - then do the stores addi $t1, $t1, _-4 addi $t0, $t0, _4 # Update first and last element addresses bgt $t1, $t0, loop # Go on till $t0 >= $t1

7. [25pt] Implementing RightRotate in MIPS Imagine that there is a MIPS instruction: sllv rd, rt, rs that causes the bits in register rt to be left-shifted by the amount indicated in register rs, and the result is put into register rd. Likewise, imagine that there is a similar instruction called "srlv", i.e. shift to the right by the amount indicated in register rs. For srlv, when shifting to the right, the content of rt is zero-extended. Using these new variable shift instructions, write a MIPS FUNCTION called "RightRotate" by filling the blanks. It accepts two arguments: $a0 contains the bit string to be rotated. $a1 contains the number of bits by which to rotate the string. (Assume that $a1 contains a positive integer between 0 and 31: 0 <= $a1 <= 31.) The bits that are rotated out of the number are again inserted to the beginning of the results. For example, rotating to the right by a single bit is shown in the diagram below: In this case, the last 0 was inserted to the beginning of the result. Your function should adhere to all function conventions and return properly with the rotated result in the proper register. RightRotate: srlv $t0, $a0, $a1 # shift to the right by the amount defined by $a1. addi $t1, $0, 32 sub $t1, $t1, $a1 sllv $v0, $a0, _$t1 # shift to the left by some amount together or $v0, _$v0, _$t0 # combine two results jr $ra # function returns

8.[5pt] Assembly Programming Instructions to perform divisions Assume that we want to divide the number contained in register $s0 by 16 and save the result in register $s1. Choose the right instruction(s) to do that ( Select all that apply) a) addi $t0, $zero, 16 div $s0, $t0 mflo $s1 a) & d) b) sll $s1, $s0, 4 c) sra $s1, $s0, 2 d) sra $s1, $s0, 4 e) none of the above