University of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)

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

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

ECE 30 Introduction to Computer Engineering

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

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

Lecture 4: MIPS Instruction Set

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

MIPS Coding Continued

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

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

MIPS%Assembly% E155%

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

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

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

Chapter 2. Instructions:

Instructions: Language of the Computer

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

Chapter 2: Instructions:

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

Computer Architecture I Midterm I

Lecture 5: Procedure Calls

CS61C : Machine Structures

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

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

Reduced Instruction Set Computer (RISC)

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

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

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

Computer Architecture

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

ECE 154A Introduction to. Fall 2012

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

Lectures 3-4: MIPS instructions

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

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Processor design - MIPS

Computer Organization and Components

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

ECE 15B Computer Organization Spring 2010

ECE232: Hardware Organization and Design

Review of instruction set architectures

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

Reduced Instruction Set Computer (RISC)

MIPS Reference Guide

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

Chapter 2A Instructions: Language of the Computer

ECE260: Fundamentals of Computer Engineering

CS 4200/5200 Computer Architecture I

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

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

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS222: MIPS Instruction Set

Computer Architecture. MIPS Instruction Set Architecture

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

CS3350B Computer Architecture MIPS Introduction

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

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

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

EE 361 University of Hawaii Fall

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

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

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

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

CS 351 Exam 2 Mon. 11/2/2015

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

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

We will study the MIPS assembly language as an exemplar of the concept.

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

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

MIPS Instruction Set

MIPS Instruction Reference

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

SPIM Instruction Set

Chapter 3. Instructions:

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

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

CS3350B Computer Architecture

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

MIPS Functions and the Runtime Stack

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

Computer Architecture. The Language of the Machine

MIPS Memory Access Instructions

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

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

Course Administration

CSE Lecture In Class Example Handout

CS/COE1541: Introduction to Computer Architecture

F. Appendix 6 MIPS Instruction Reference

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

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

CENG3420 Lecture 03 Review

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

CS61C Machine Structures. Lecture 10 - MIPS Branch Instructions II. 2/8/2006 John Wawrzynek. (

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

CS3350B Computer Architecture MIPS Instruction Representation

Transcription:

University of California at Santa Barbara ECE 154A Introduction to Computer Architecture Quiz #1 October 30 th, 2012 Name (Last, First) All grades will be posted on the website as a single spreadsheet file. For anonymity please provide class id (which you will remember) which will be used instead of your name or university ID when posting grades. The class id could be any combination of symbols of <8 length. Your class ID: Page 1 of 6

Problem #1 (20 points) Write MIPS assembler code which would check whether the data are stored in little or big endian formats in external memory. After execution of your code register $t0 should have value 0 if the external memory is little endian and 1 if it is big endian. Any temporary registers ($t0 $t9) and instructions from green card can be used for this problem. Only valid memory locations can be used for testing purposes, e.g. those used for register spilling. (Note that, in general, assembler language is a platform dependent so such code is rarely needed) There could be various ways to do that. The main idea is to store word with test content, i.e. having hex value 0x000 0001, using stack pointer ($sp) and then check the order of how it was stored by loading byte value from the stack and performing simple comparison. For example, the following code will do the job even without any comparison addi $t0, $0, 0x0001 sw $t0, 4($sp) lb $t0, 1($sp) Note that stack grows from higher address down and to use stack you have to advance the pointer first, i.e. subtract 4 or use immediate offset 4. It is unsafe to use stack without advancing the pointer 0($sp) because you may destroy the stored value needed by other part of the program. Page 2 of 6

Problem #2 (30 points) (a) (20 points) Translate the following MIPS code into equivalent C code addi $v0, $0, 0 Loop: andi $t0, $a0, 1 add $v0, $v0, $t0 srl $a0, $a0, 1 bne $a0, $0, Loop Here the same variable names are used in c code as that of corresponding registers in assembler v0 = 0; do { v0 = v0 + a0 & 1; a0 = a0 >> 1; } while (a0!=0); Note that do{body} while(cond) is not the same as while(cond){body}! (b) (5 points) Briefly explain in English what the code does Counts the number of 1 s in register $a0, i.e. population count (c) (5 points) Assuming 32 bit MIPS architecture what is the maximum and the minimum number of instructions (i.e. dynamic count) which can be executed by this code? Minimum is when value of register $a0 is 0, i.e. 1 + 4*1 = 5 Maximum is when value of the most significant bit of register $a0 is 1, i.e. 1 + 4*32 = 129 Page 3 of 6

Problem 3 (30 points) Translate the following C code into equivalent MIPS one: for ( i = 0; i < 10; i++) b[i] = ( a[i] + a[i+10] ) << 1 ; Assume the base addresses for the arrays a and b are in $a0 and $a1, correspondingly. Do while constructions style (for loop is also okay for full credit) addi $t0, $a0, 40 LOOP: lw $t1, 0($a0) lw $t2, 40($a0) addi $a0, $a0, 4 addi $a1, $a1, 4 add $t1, $t1, $t2 sll $t1, $t1, 1 sw $t1, 4($a1) bne $a0, $t0, LOOP Page 4 of 6

Problem 4 (20 points) Given your understanding of PC relative addressing, explain why an assembler might have problems directly implementing the branch instruction in the following code sequence: here: beq $s0, $s2, there there: add $t2, $t1, $t0 Show how the assembler might rewrite this code sequence to solve these problems. There is a limitation to how far bne instruction can jump because the immediate field is only 16 bits. More specifically, for any I type control flow instruction the range is 216+2 instructions. Note the 4 times larger range because of the shifting of the immediate value when calculating the physical address (this is due to the fact that all instructions are word aligned in memory). The range is much larger for J type instructions. With 26 bits in J type instruction it is 228 which is still not the maximum possible one. The maximum range is provided by jr rs instruction which jumps to the address provided by 32 bit value in rs register. Therefore, e.g., assuming J type instruction, assembler could rewrite the following sequence as here: bne $s0, $s2, skip j there skip: there: add $t2, $t1, $t0 Page 5 of 6

Bonus Problem 5 (10 points) Suppose that you need to implement swapping of the content between registers $t0 and $t1 and only these two registers are available. (For example, it could be a situation when one wants to avoid register spilling to improve execution time). Write your code for this operation. version 1: xor $t0, $t0, $t1 xor $t1, $t0, $t1 xor $t0, $t1, $t0 version 2: addu $t0, $t0, $t1 subu $t1, $t0, $t1 subu $t0, $t0, $t1 Page 6 of 6