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

Similar documents
ECE 30 Introduction to Computer Engineering

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

CDA3100 Midterm Exam, Summer 2013

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

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

MIPS function continued

Midterm. CS64 Spring Midterm Exam

CSE 2021: Computer Organization

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

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

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

MIPS Instruction Reference

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

Lecture 6 Decision + Shift + I/O

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

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

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

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

F. Appendix 6 MIPS Instruction Reference

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

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

MIPS%Assembly% E155%

Compiling Techniques

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

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

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

MIPS Assembly Programming

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

2B 52 AB CA 3E A1 +29 A B C. CS120 Fall 2018 Final Prep and super secret quiz 9

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

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

MIPS Reference Guide

MIPS Coding Continued

Assembly Programming

Introduction to MIPS Processor

Examples of branch instructions

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

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

Shift and Rotate Instructions

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

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

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

Flow of Control -- Conditional branch instructions

Mips Code Examples Peter Rounce

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

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

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

Common Problems on Homework

Programming the processor

CS3350B Computer Architecture MIPS Introduction

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

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

CS3350B Computer Architecture MIPS Instruction Representation

CS 61c: Great Ideas in Computer Architecture

CSc 256 Midterm 1 Fall 2011

CPS311 - COMPUTER ORGANIZATION. A bit of history

Computer Architecture. The Language of the Machine

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

LAB B Translating Code to Assembly

Lecture 7: Examples, MARS, Arithmetic

Computer Architecture I Midterm I

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

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

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

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

CSc 256 Midterm (green) Fall 2018

Reduced Instruction Set Computer (RISC)

Assembler. Lecture 8 CS301

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

MIPS Instruction Set

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

Lectures 3-4: MIPS instructions

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Reduced Instruction Set Computer (RISC)

Lecture 4: MIPS Instruction Set

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

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

Computer Organization and Components

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

MIPS Assembly Language. Today s Lecture

EE 361 University of Hawaii Fall

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

SPIM Instruction Set

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

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

Solutions for Chapter 2 Exercises

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

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

ECE260: Fundamentals of Computer Engineering

CS61c MIDTERM EXAM: 3/17/99

Course Administration

Chapter 2. Instructions:

ECE331: Hardware Organization and Design

Computer Organization MIPS ISA

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

Computer Architecture

Week 10: Assembly Programming

CS3350B Computer Architecture

CS 61c: Great Ideas in Computer Architecture

Lecture 5: Procedure Calls

Transcription:

CSE 2021: Computer Organization Assignment # 1: MIPS Programming Due Date: October 25, 2010 Please note that a short quiz based on Assignment 1 will be held in class on October 27, 2010 to assess your performance. It is not required that you submit your solution but you should complete the assignment in preparation for the quiz. Problems 1 to 3 are fairly trivial programs and the challenge is to complete each of them in 15 to 30 minutes or so in anticipation of the preparation for the coming midterm exam. Likewise, the theoretical questions (Problem 4) in the attached mid term exam should not, collectively, take more than 90 minutes of your time. Good luck! Problem 1: Write a program that reads a valid date (3 integers being date (d), month (m), year (y)) and determines the day of the week (Sun, Mon, Tue, etc.) using the Zeller's algorithm described below: if (m <= 2){ m = m + 12; y = y - 1; } tmp1 = (26 * (m + 1)) / 10; tmp2 = (125 * y) / 100; tmp3 = d + tmp1 + tmp2 (y / 100) + (y / 400) - 1; dow = tmp3 % 7; The resulting integer in dow (day-of-week) denotes the day. If dow equals 0, then the day is Sunday. If dow equals 1 then the day is Monday, and so on for the rest of the days in a week. Your program should output the day in words depending on the value of dow. Hint: Recall that integer division results in only the quotient as the output with the remainder being ignored such that 190/100 = 180/100 = 101/100 = 1. Problem 2: Write a MIPS assembly program that accepts the temperature in Celsius as the input and converts the input reading from Celsius to Fahrenheit. Since the answer can be a real number so use the instructions of the floatingpoint coprocessor to compute your answer. The formula to convert Celsius to Fahrenheit is given by and the program should keep running until any character is entered. Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

Group-A For each question, write the contents of the indicated register pair (in the specified radix) after the fragment executes. For decimal radix, state the content as a signed integer. If an answer cannot be determined or the fragment has errors, write a brief explanation. A.1 addi $t1, $0, 25 addi $t2, $0, 17 div $t1, $t2 mflo $t3 A.2 addi $t1, $0, 25 addi $t2, $0, 3 bgtz $t1, here addi $t2, $0, 17 here: addi $t3, $0, 8 A.3 addi $t3, $0, 5 addi $t2, $0, 3 here: add $t3, $t3, $t3 addi $t2, $t2, -1 bne $t2, $0, here CSE2021/HR MIDTERM EXERCISES PAGE 1

A.4 main: lui $t2, 0x1 ori $t3, $t2, 0xff $t2 (in hex) = $t3 (in hex) = A.5 addi $t1, $0, 25 addi $t2, $0, 3 sll $t2, $t2, 3 and $t3, $t1, $t2 A.6.data a:.asciiz "2021" x:.byte 7,2,12.text main: addi $t2, $0, 1 lb $t3, a($t2) A.7.data a:.asciiz "2021" x:.byte 7,2,12.text main: la $t1, x lb $t2, 0($t1) lb $t3, 2($t1) CSE2021/HR MIDTERM EXERCISES PAGE 2

A.8.data a:.word 12,-5,4,0 x:.byte 5.text main: addi $t1, $0, 8 lw $t2, a($0) lw $t3, a($t1) A.9.data a:.word 12,-5,4,0 x:.byte 5, 1, -5, -1.text main: addi $t2, $0, 16 lb $t3, a($t2) A.10 addi $t1, $0, 5 sll $t2, $t1, 29 sra $t3, $t2, 29 $t2 (in hex) = $t3 (in hex) = CSE2021/HR MIDTERM EXERCISES PAGE 3

Group-B Unless stated otherwise, assume the machine is little endian, the integers in question are signed, and all operations result in values that fit in 32 bits. B.1 Write a minimal sequence of MIPS instructions that accomplishes the following: if ($t1 < $t2) { $s0 = $t2; } else { $s0 = $t1 } B.2 Write a minimal sequence of MIPS instructions that accomplishes the following: a[15] = a[14] - 15; where a is an array of words already declared and initialized in.data. CSE2021/HR MIDTERM EXERCISES PAGE 4

B.3 Write the MIPS instruction whose machine language encoding is: 0000 0011 0001 1001 0100 0000 0010 1010 Your answer must use register names (like $t0) not numbers; and must specify any immediate as a signed integer in decimal. B.4 Write a minimal sequence of MIPS instructions that accomplishes the following: while (a[$t1] == $s0) { $t1 = $t1 + $t2 } where a is an array of words already declared and initialized in.data. CSE2021/HR MIDTERM EXERCISES PAGE 5

B.5 Write a sequence of MIPS instructions to branch to address 0xFFFFFFFC if $t1 is equal to $t2. Recall that the destination of j or any branch instruction must be a label, not a constant B.6 Write a minimal sequence of MIPS instructions that accomplishes the following: $t1 = 0xABCDE; CSE2021/HR MIDTERM EXERCISES PAGE 6

B.7 Write the machine language encoding of the beq instruction in the following fragment. Express your answer in binary. addi $t0, $t3, 143 sw $s0, 165($t1) beq $s4, $sp, skip sll $s0, $s0, 4 skip: sub $t0, $t3, $s0 B.8 Write a minimal sequence of MIPS instructions that accomplishes the following: $t3 = 35 * ($t1 / $t2) + 14 You can assume $t2 is not zero and that all integers are signed and small enough that the results of all operations do fit in 32 bits. CSE2021/HR MIDTERM EXERCISES PAGE 7

B.9 Write a minimal sequence of MIPS instructions that makes the least-significant bit in $a0 the same as its most-significant bit without changing any other bit in it. B.10 Write a minimal sequence of MIPS instructions that sets $v0 to the number of characters in a null-terminated string whose starting address is in $a0. Do not count the null as part of the string. CSE2021/HR MIDTERM EXERCISES PAGE 8

B.11. Write the MIPS method that receives in $a0 a positive integer X and returns in $v0 the largest integer M that satisfies the following: 1 + 4 + 9 + 16 +... + M 2 <= X In other words, M is the largest integer such that the sum of the squares of the first M integers is not more than X. For example, if X=79 then M would be 5 because the sum 1+4+9+16+25 is 55, and had we added one more term (36), the sum (91) would have exceeded X. You can assume that the integer in $a0 is positive, and that all integers are signed and small enough that the individual squares and the final sum do fit in 32 bits. B.12. Write a MIPS program that reads an integer from the user and outputs 1 if the integer is magical and outputs 0 otherwise. To determine if the integer is magical we will invoke a method called "ismagical" from the main program by writing "jal ismagical". We do not know what makes the integer magical, in other words we have not inspected the method "ismagical" although it has already been written and its code will be placed at the end of our MIPS code as shown on the next page. However, the communication between the main program and the method is known to us and will be done through the stack, not via registers as in most of our examples in class. When the method receives control, that is, at the instant we jump to the method from the main program, the stack will have three words on it: the first contains the address of a word in memory in which the user-entered integer is stored, the second contains the address in memory of a byte where the answer (0 or 1) should be stored, and the third contains the return address (the method will return to it when it ends, not to $ra). As an example let us assume that the stack pointer ($sp) is equal to 400 when the method receives control, and that the stack content is as shown in the diagram to the right. In that case the address of the user-entered integer is 800, the method should store the answer in the byte at address 600, and when the method ends it should jump to the instruction at address 12000. 396 400 12000 404 600 408 800 Write the main program on the next page. The main program should be general and not depend on any specific example numbers. CSE2021/HR MIDTERM EXERCISES PAGE 9

B.12, continued..data.text main: addi $v0, $0, 5 syscall # read an int into $v0 #----------------------------------------------- # if $v0 is magical set $s0 = 1 else set $s0 = 0 #----------------------------------------------- #----------------------------------------------- add $a0, $s0, $0 addi $v0, $0, 1 syscall # print s0 jr $ra # end the program ismagical: #----------------------------------------------- already written.. CSE2021/HR MIDTERM EXERCISES PAGE 10

Group-C C.1 Why does MIPS not have a subtract immediate instruction? C.2 Recall that according to the IEEE-754 standard a single precision real number is represented in one word using 1+8+23 bits. How many such numbers are there between 2.0 and 3.0, and how many are between 1000002.0 and 1000003.0? Approximate answers are acceptable but you must show your work. C.3 Suppose that a company conducts surveys whose answers always have three possibilities, yes, no, and do not know. The company wants to store these surveys in a new kind of memory in which the smallest unit (similar to a bit) is known as a trit and can be 0, 1 or 2. How many trits are required to hold a 6 bit number? Give an expression for the number of trits needed to hold n bits. C.4 What are pseudo instructions and what is their purpose? Give examples. C.5 MIPS has added a shift-right-arithmetic instruction so that signed two's complement numbers can be divided by two whenever shifted to the right. Why is there no corresponding shift-left-arithmetic instruction? CSE2021/HR MIDTERM EXERCISES PAGE 11