CS 2504 Intro Computer Organization Test 1

Similar documents
CS 2506 Computer Organization II

CS 2506 Computer Organization II

CS 2506 Computer Organization II Test 1. Do not start the test until instructed to do so! printed

CS 2506 Computer Organization II Test 2

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

MIPS Coding Continued

Course Administration

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

Lecture 5: Procedure Calls

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

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

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

Chapter 2A Instructions: Language of the Computer

MIPS%Assembly% E155%

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

Thomas Polzer Institut für Technische Informatik

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

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

Lab 3 (All Sections) Prelab: MIPS-Control Instructions

Assembler. Lecture 8 CS301

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

Chapter 2: Instructions:

Lab 3 (Sections 300, 301 and 302) Prelab: MIPS-Control Instructions

Computer Organization MIPS ISA

ECE232: Hardware Organization and Design

Lecture 4: MIPS Instruction Set

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

MIPS Functions and Instruction Formats

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instructions: Language of the Computer

Topic Notes: MIPS Instruction Set Architecture

CS 2506 Computer Organization II Test 1

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

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

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

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

Unsigned Binary Integers

Unsigned Binary Integers

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

Lab 4 : MIPS Function Calls

CS 61c: Great Ideas in Computer Architecture

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

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

Stack Memory. item (16-bit) to be pushed. item (16-bit) most recent

Solution printed. Do not start the test until instructed to do so! CS 2504 Intro Computer Organization Test 2 Spring 2006.

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

Computer Architecture

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

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

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

Do not start the test until instructed to do so!

Instructions: Language of the Computer

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

CSE 378 Midterm 2/12/10 Sample Solution

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

CDA3100 Midterm Exam, Summer 2013

CS 2505 Computer Organization I

CS222: MIPS Instruction Set

CS 2506 Computer Organization II Test 2. Do not start the test until instructed to do so! printed

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

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

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

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

Instruction Set Architectures Part I: From C to MIPS. Readings:

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

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Do not start the test until instructed to do so!

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

EE 361 University of Hawaii Fall

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I

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

Chapter 2. Instructions:

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

Control Instructions

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

CS 2506 Computer Organization II Test 2. Do not start the test until instructed to do so! printed

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

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

Chapter 2. Instruction Set Architecture (ISA)

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

Do not start the test until instructed to do so!

ECE 30 Introduction to Computer Engineering

CENG3420 Lecture 03 Review

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

Instructions: Assembly Language

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Chapter 4. The Processor

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

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

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

Systems Architecture I

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

Transcription:

Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet and the MIPS reference card. No calculators or other computing devices may be used. Answer each question in the space provided. If you need to continue an answer onto the back of a page, clearly indicate that and label the continuation with the question number. If you want partial credit, justify your answers, even when justification is not explicitly required. There are 6 questions, priced as marked. The maximum score is 100. When you have completed the test, sign the pledge at the bottom of this page and turn in the test. Note that either failing to return this test, or discussing its content with a student who has not taken it is a violation of the Honor Code. Do not start the test until instructed to do so! Name Solution printed Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signed 1

1. [16 points] The native MIPS assembly language does not include a nand (not-and) instruction: nand $rd, $rs, $rt # $rd <--!($rs && $rt) in bitwise fashion Show how an assembler might replace the pseudo-instruction above with a sequence of one or more native instructions to achieve the same effect. Include comments to explain the logic of your design, and be sure to observe any relevant register conventions. Here's one solution (there are a number of others): and $at, $rs, $rt # form $rs & $rt nor $rd, $at, $at # x nor x == ~(x or x) # == ~x and ~x # == ~x Note that no solution should modify any registers except $rd and, possibly $at. Some alternate solutions can be based on the following facts: A xor 1 == ~A (bitwise) and so ($rs and $rt) xor 0xFFFFFFFF == $rs nand $rt A nor 0 == ~A (bitwise) and so ($rs and $rt) nor $zero == $rs nand $rt $rs nand $rt == ~($rs and $rt) == (~$rs) or (~$rt) == ($rs nor $rs) or ($rt nor $rt) # Native logical instr: and $rd, $rs, $rt nor $rd, $rs, $rt or $rd, $rs, $rt xor $rd, $rs, $rt 2. [16 points] Assume the following data segment of a MIPS assembly program: Size:.word 10 List:.word 2, 3, 5, 7, 9, 11, 13, 17, 19, 23 Write MIPS assembly instructions to transfer the fourth word of the array List (i.e., 7) into register $s0. There are a number of solutions. Here are four: soln1: la lw $t0, List $s0, 12($t0) soln2: la $t0, List li $t1, 3 sll $t1, $t1, 2 add $t1, $t1, $t0 lw $s0, ($t1) soln3: lw $s0, List + 12 soln4: li $t1, 12 lw $s0, List($t1) 2

3. Consider the following MIPS assembly code fragment: Adddress Assembly Instruction ---------------------------------------------- [0x00400100] loop: blez $t0, done #1 [0x00400104] addi $t0, $t0, -4 #2... [0x0040017C] b loop #3 [0x00400180] done: li $t1, 1000 #4 a) [2 points] What is the value of the program counter register when the system begins to execute the instruction in line #1? At the beginning of execution, PC = 0x00400100. While the opcode is being decoded, the PC will be incremented by 4. b) [8 points] Describe carefully what possible values the program counter may have after the instruction shown in line #1 is executed, and why. if $t0 <= 0 then PC <-- 0x00400180 else PC <-- 0x00400104 c) [6 points] If the instruction in line #1 is executed and the value in $t0 is 0, what value must be added to the program counter? Give your answer in hexadecimal. By the time the registers have been compared, the PC will already have been incremented by 4. So, if $t0 == 0 then the value added to the PC must equal 0x00400180 0x00400104 = 0x7C 3

4. [20 points] Complete the following MIPS assembly procedure, which shifts elements of the array parameter to delete the specified element from an array. Your solution should not make use of the stack. Comment your code to explain the logical significance of each statement. ############################################################################### # Pre: $a0 points to the array in question # $a1 points to the size of the array # $a2 specifies the C-style index of the element to be deleted # # Post: $a0 is unchanged # $a1 is unchanged # $a2 the target of $a2 has been decremented # The element of the array at the specified index has been deleted # $v0 == 1 if deletion is successful; $v0 == 0 otherwise # arraydelete: # check whether the index is in bounds blt $a2, $zero, fail lw $t0, 0($a1) # $t0 stores the size of the array blt $a2, $t0, del # see if target index is in range fail: li $v0, 0 # if not, set fail code and return j exit del: # iterate from $a2 to next-to-last element, shifting as we go addi $t0, $t0, -1 # calculate terminal index for traversal move $t1, $a2 # $t1 tracks current leading index beq $t1, $t0, decr # if last elem, no need to shift move $t3, $a0 # $t3 points to current leading elem move $t4, $t1 sll $t4, $t4, 2 add $t3, $t3, $t4 # $t3 points to arr[$a2] loop: lw $t4, 4($t3) sw $t4, 0($t3) addi $t3, $t3, 4 addi $t1, $t1, 1 blt $t1, $t0, loop decr: sw $t0, 0($a1) # grab next element to shift # store it in previous array cell # step pointer forward # count elem just shifted # decrement array size li $v0, 1 exit: jr $ra Note that if the element to be deleted is at the end of the array then no shifting takes place; if you don't pre-test for this (as shown above) then you'll probably access a memory location past the end of the array. 4

5. [16 points] The author of a MIPS assembly program needs to push the elements of the array Stuff and the size of the array (from the data segment given below) onto the stack. The initial and resulting states of the stack are shown below:.data Sz:.word <value not specified> Stuff:.word <list of Sz integer values> Initial stack: ------------------ unknown data <-- sp ------------------ Final stack: unknown data List[0] List[1]... List[Sz-1] size of List <-- sp Write MIPS assembly instructions to modify the stack exactly as described above. Your solution should be general in the sense that it should not depend on any specific values for Sz or the list elements. Comment your code to explain the logical significance of each statement. lw $t0, Sz # get array size li $t1, 0 # set loop counter la $s0, Stuff # get pointer to first array elem loop: beq $t1, $t0, endloop # exit loop when reach final elem lw $s1, 0($s0) # load current array elem addi $sp, $sp, -4 # alloc room on stack for current elem sw $s1, 0($sp) # push current array elem to stack addi $s0, $s0, 4 # move pointer to next array elem addi $t1, $t1, 1 # count current elem b loop # restart loop endloop: addi $sp, $sp, -4 # alloc room on stack for array size sw $t0, 0($sp) # push array size to stack Note that it is logically necessary to perform a test before entering the loop, in case the size of the array is zero. 5

6. In MIPS machine language, the I-format and R-format instructions have the following formats: I: 31 opcode srcreg_1 srcreg_2 offset 26 25 2120 16 15 0 R: opcode srcreg_1 srcreg_2 destreg shamt funct 31 26 25 2120 16 15 11 10 6 5 0 a) [8 points] One of the design principles that guided the development of the MIPS platform was that "simplicity favors regularity". In other words, in order to promote simplicity in a system, the designer should look for opportunities to use the same design patterns over and over. Discuss how this principle is illustrated by the MIPS machine language formats above. both formats place the opcode in bits 31:26 both formats place the two source registers into bits 25:21 and 20:16 b) [8 points] Discuss how the fact that the offset field in the definition of the I-format is 16 bits wide imposes a compromise on the implementation of the conditional branch instructions. The offset is limited to the approximate range "jump". 15 ± 2, which limits the distance that a conditional branch can The limitation can be mitigated somewhat by making the "jump" be relative to the current value of the PC and interpreting it as the number of words to jump rather than the number of bytes, raising the relative distance that can be "jumped". 6