Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Homework 5 Solutions - Computer Architecture I | CSE 30321, Assignments of Computer Architecture and Organization

Material Type: Assignment; Class: Computer Architecture I; Subject: Computer Science and Engr.; University: Notre Dame; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-xdk
koofers-user-xdk 🇺🇸

10 documents

1 / 5

Toggle sidebar

Related documents


Partial preview of the text

Download Homework 5 Solutions - Computer Architecture I | CSE 30321 and more Assignments Computer Architecture and Organization in PDF only on Docsity! CSE30321 Computer Architecture I Fall 2008 Homework 05: MIPS (100 Points) Assigned: September 30 Due: Oct 7 This homework will delve deeper into MIPS assembly. Now that we have covered the MIPS procedure call conventions in class, it is possible to write some real code that could, hypothetically, interface with C code on a real MIPS system. This assignment should be done in groups of 3-4 people. Please consult the guidelines given in the syllabus on performing group assignments. Each team only needs to turn in one solution together with a cover sheet indicating the role of each team member. 1. (15 Points) Consider the following fragment of C code: for (i = 0; i <= 100; i = i + 1) a[i] = b[i] + c[i]; Assume that a, b, and c are arrays of words (ints) and the base address of a is in $a0, b is in $a1 and c is in $a2. Register $t0 is associated with variable i. You may also assume that any address constants you need are available to be loaded from memory. Write the code for MIPS. How many instructions are executed if there are no array out-of-bounds exceptions (i.e., all array accesses are valid)? How many memory data references will be made during execution (excluding instruction fetches)? Solution This is one possible solution (from the 2007 version of the homework): To test for loop termination, the constant 401 is needed. Assume that it is placed in memory when the program is loaded: lw $t8, AddressConstant401($zero) # $t8 = 401 add $t0, $zero, $zero # initialize i = 0 Loop: add $t1, $a1, $t0 # $t1 = address of b[i] add $t2, $a2, $t0 # $t2 = address of c[i] lw $t3, 0($t1) # $t3 = b[i] lw $t4, 0($t2) # $t4 = c[i] add $t5, $t3, $t4 # $t5 = b[i] + c[i] add $t6, $a0, $t0 # $t6 = address of a[i] sw $t5, 0($t6) # a[i] = b[i] + c[i] addi $t0, $t0, 4 # i = i + 4 slt $t7, $t0, $t8 # $t7 = 1 if $t0 < 401 bne $t7, $zero, Loop # goto Loop if i <= 401 1 The number of instructions executed is 2 + 101 x 10 = 1012 instructions. The number of data references made is 1 + 101 x 3 = 304 references. 2. (15 Points) When designing memory systems, it is useful to know the frequency of memory reads versus writes as well as the frequency of accesses for instructions versus data. Using the average instruction mix information for MIPS for the program SPEC2000int in Figure 2.48 (page 146), find the following: (a) The percentage of all memory accesses (both data and instruction) that are for data. (b) The percentage of all memory accesses (both data and instruction) that are for reads. Assume that two-thirds of data transfers are loads. Note: Don’t forget that to fetch instructions, memory needs to be accessed. Solution From Figure 2.48 (page 146), 36% of all instructions for SPEC2000int are data access in- structions. Thus, for every 100 instructions there are 36 data accesses, yielding a total of 136 memory accesses (1 to read each instruction, and 36 to access data). (a) The percentage of all memory acceses that are for data = 36/136 = 26%. (b) Assuming two-thirds of data transfers are loads, the percentage of all memory accesses that are reads = (100 + (36 × 2/3))/136 = 91% 3. (10 Points) Suppose we have made the following measurements of average CPI for the MIPS instructions: Instruction Average CPI Arithmetic and Logical 1.0 clock cycles Data transfer (load and store types) 1.4 clock cycles Conditional Branch 1.7 clock cycles Jump 1.2 clock cycles Compute the effective CPI for the MIPS processor to execute SPEC2000 benchmark pro- grams. Assume that the average of the instruction frequencies for SPEC2000int and SPEC2000fp in Figure 2.48 on page 146 is used to represent the instruction mix. Solution Effective CPI = Sum of (CPI instruction type × Frequency of executation) The average instruction frequencies for SPEC2000int and SPEC2000fp are 0.47 arithmetic (0.36 arithmetic and 0.11 logical), 0.375 data transfer, 0.12 conditional branch, 0.015 jump. Thus the effective CPI = 0.47 × 1.0 + 0.375 × 1.4 + 0.12 × 1.7 + 0.015 × 1.2 = 1.2. 4. (25 Points) The code below performs a mergesort of an array that has a power-of-two size. We assume that we have an external routine merge() that merges two sorted arrays into one sorted array 2
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved