DOC PREVIEW
U of I CS 232 - Review 1

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS232 Fall 2006 Midterm 1 reviewThese problems are drawn from past exams. Solutions can be found on the class website:http://www.cs.uiuc.edu/class/fa06/cs232/exams/1. C to MIPS, Spring 2005 Problem 2:The following recursive C function counts the number of bits that are set (i.e. equal to1) in the given input word. Translate this function into MIPS. You must use recursion,and you must follow the calling conventions.int recursive_bit_count(int input_word) {if (input_word == 0)return 0;int lowest_bit = input_word & 1;return lowest_bit + recursive_bit_count(input_word >> 1);}2. Debugging MIPS, Spring 01: Little Howie is having a bad day. He has a C functionwhich returns the smallest integer in an array V of n elements. However, when LittleHowie translated the function into MIPS assembly language, he made several logical (notsyntax) errors. Help Little Howie by finding and fixing at least four distinct errors in hisfunction. Both the correct C code and the buggy MIPS code are shown below. Indicatethe bugs and fixes directly on the assembly program.int minimum(int V[], int n) // Find smallest integer in an array V with n elements{int min, i;min = V[0]; // min is initialized with the first element of Vfor (i=1; i<n; i++)if (V[i] < min) // Found an element smaller than the current minmin = V[i];return min;}minimum: # $a0 contains "V"addi $sp, $sp, -4sw $t0, 0($sp)lw $s0, 0($a0) # $s0 is "min"li $s1, 1 # $s1 is "i"loop:bgt $s1, $a1, exitadd $t0, $s1, $a0lw $t0, 0($t0) # Load element of arraybgt $t0, $s0, nextmove $s0, $t0 # New "min" valuenext:addi $s1, $s1, 1j loopexit:addi $sp, $sp, 4lw $t0, 0($sp)jr $ra1CS232 Fall 2006 Midterm 1 review3. CPU Performance, Fall 03: The following piece of MIPS code writes $a1 zeroes intoan array of bytes with base address $a0:bzero:beq $a1, $zero, endloop:sb $zero, 0($a0)add $a0, $a0, 1sub $a1, $a1, 1bne $a1, $zero, loopend:jr $ra(a) Given a 2GHz processor (cycle time 0.5ns) with the CPIs as given below, what wouldbe the exact CPU time of this function if it were clearing an array of 25 bytes?add, sub have CPI = 3, lb, sb have CPI = 5, all branches have CPI = 4(b) Compute the average CPI for this function. You can leave your answer as a fraction.(c) If we could reduce the CPI of one instruction class (arithmetic, memory, or control)by a single cycle, which would most benefit the given code?(d) When zeroing out large memory regions it is more efficient to use sw (store word)rather than sb (store byte) because we can do four times as much work in a singleinstruction. But sw alone can only handle strings with lengths divisible by 4. Belowis a version of the code that only uses sb to handle the last few bytes for stringswhose length is not evenly divisible by 4.bzero:blt $a1, 4, bytesL1:sw $zero, 4($a0)add $a0, $a0, 4sub $a1, $a1, 4bge $a1, 4, L1bytes:beq $a1, $zero, endL2:sb $zero, 0($a0)add $a0, $a0, 1sub $a1, $a1, 1bne $a1, $zero, L2end:jr $raGive an example of a case when the new code will be slower than the original code.4. Conceptual questions, Spring 05, Fall 04, Fall 03:(a) What is abstraction? How does it relate to instruction set architectures (ISAs)?(b) Explain how a machine knows whether to interpret a group of bits as an integer, afloating point number, or an instruction.(c) What advantages does using interrupts have over polling?(d) What advantages does polling have over using interrupts?(e) Motorola unveils a new processor design, the M-232, that runs at 10GHz thanksto a sleek new ISA. What additional information do you need to know how muchfaster (or slower) the M-232 is than a 3GHz Pentium4 when running the


View Full Document

U of I CS 232 - Review 1

Documents in this Course
Goal

Goal

2 pages

Exam 1

Exam 1

5 pages

Exam 1

Exam 1

6 pages

Exam 2

Exam 2

6 pages

Exam 1

Exam 1

5 pages

Load more
Download Review 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Review 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Review 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?