DOC PREVIEW
U of I CS 232 - Exam 1

This preview shows page 1-2 out of 5 pages.

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

Unformatted text preview:

1CS232 Exam 1February 20, 2003Name: This exam has 5 pages, including this cover. There are three questions, worth a total of 100 points. The last page is a summary of the MIPS instruction set, whichyou may remove for your convenience. No other written references or calculators are allowed. Write clearly and show your work. State any assumptions you make. You have 50 minutes. Budget your time, and good luck!100Total153452401Your ScoreMaximumQuestion2Question 1: Understanding MIPS programs (40 points)func:li $v0, 0li $t0, 0L1: add $t1, $a0, $t0lb $t2, 0($t1)beq $t2, $zero, L3bne $t2, $a1, L2add $v0, $v0, 1L2: add $t0, $t0, 1j L1L3: jr $raPart (a)Translate the function func above into a high-level language like C or Java. You should include a headerthat lists the types of any arguments and return values. Also, your code should be as concise as possible,without any gotos or pointers. We will not deduct points for syntax errors unless they are significant enoughto alter the meaning of your code. (30 points)Part (b)Describe briefly, in English, what this function does. (10 points)3Question 2: Write a recursive function (45 points)Here is a function is_prime_rec that takes two arguments (i and P, both 32-bit numbers) and returns aninteger; 1 is returned if P is found to be prime, otherwise 0 is returned. This function is used by the functionis_prime.Translate is_prime_rec into a MIPS assembly language function. You do not need to translateis_prime!! Argument registers $a0 and $a1 will correspond to i and P, and the return value should beplaced in $v0 as usual. Use the rem pseudoinstruction for the mod (%) operator .Your implementation must be recursive. You will not be graded on the efficiency of your code, but youmust follow all MIPS conventions. Comment your code!!!intis_prime(int P) { return is_prime_rec(P-1, P);}intis_prime_rec(int i, int P) { if (i <= 1) return 0; if ((P % i) == 0) return 1; return is_prime_rec(i-1, P);}4Question 3: Concepts (15 points)Write a short answer to the following questions. For full credit, answers should not be longer than twosentences.Part a) What is abstraction? How does it relate to instruction set architectures (ISAs)? (5 points)Part b) In section, we saw code like the following:li $a0, 1mtc1 $a0, $f1cvt.s.w $f1, $f1What does this code do, and, specifically, what role does the third instruction play? (5 points)Part c) What advantages does using interrupts have over polling? (5 points)5MIPS instructionsThese are some of the most common MIPS instructions and pseudo-instructions, and should be all youneed. However, you are free to use any valid MIPS instructions or pseudo-instruction in your programs.The second source operand of the arithmetic and branch instructions may be a constant.Register ConventionsThe caller is responsible for saving any of the following registers that it needs, before invoking a function.$t0-$t9 $a0-$a3 $v0-$v1The callee is responsible for saving and restoring any of the following registers that it uses.$s0-$s7 $ra$ra = PC + 4; go to Labeljal Labelgo to address in $rajr $rago to Labelj LabelJumpif ($t1 < 100) then $t0 = 1 else $t0 = 0slti $t0, $t1, 100if ($t1 < $t2) then $t0 = 1 else $t0 = 0slt $t0, $t1, $t2Setif ($t0 < $t1) go to Labelblt $t0, $t1, Labelif ($t0 ≤ $t1) go to Labelble $t0, $t1, Labelif ($t0 > $t1) go to Labelbgt $t0, $t1, Labelif ($t0 ≥ $t1) go to Labelbge $t0, $t1, Labelif ($t0 ≠ $t1) go to Labelbne $t0, $t1, Labelif ($t0 = $t1) go to Labelbeq $t0, $t1, LabelBranchMem[100 + $t1] = $t0sw $t0, 100($t1)$t0 = Mem[100 + $t1]lw $t0, 100($t1)Data Transfer$t0 = 100li $t0, 100$t0 = $t1move $t0, $t1Register Setting$t0 = $t1 mod $t2rem $t0, $t1, $t2$t0 = $t1 / $t2div $t0, $t1, $t2$t0 = $t1 x $t2mul $t0, $t1, $t2$t0 = $t1 + 100addi $t0, $t1, 100$t0 = $t1 – $t2sub $t0, $t1, $t2$t0 = $t1 + $t2add $t0, $t1, $t2ArithmeticMeaningExample


View Full Document

U of I CS 232 - Exam 1

Documents in this Course
Goal

Goal

2 pages

Exam 1

Exam 1

6 pages

Exam 2

Exam 2

6 pages

Exam 1

Exam 1

5 pages

Load more
Download Exam 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 Exam 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 Exam 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?