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:

CS232 Exam 1 September 29, 2004Question 1: Understanding MIPS programs (40 points)Question 2: Write a MIPS function (45 points)Question 3: Concepts (15 points)MIPS instructions1CS232 Exam 1September 29, 2004Name: 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!Question Maximum Your Score1 402 453 15Total 1002Question 1: Understanding MIPS programs (40 points)enchilada: li $v0, 0li $t0, 0li $t1, 0mole: bge $t1, $a1, tapasmul $t2, $t1, 4add $t2, $t2, $a0lw $t3, 0($t2)ble $t3, $t0, quesomove $v0, $t1move $t0, $t3queso: add $t1, $t1, 1j moletapas: jr $raPart (a)Translate the function enchilada above into a high-level language like C or Java. You should include a header that lists the types of any arguments and return values. Also, your code should be as concise as possible, without any gotos or pointer arithmetic. We will not deduct points for syntax errors unless they are significant enough to alter the meaning of your code. (30 points) Part (b)Describe briefly, in English, what this function does. (10 points)3Question 2: Write a MIPS function (45 points)Here is a function random_anagram that takes two arguments (str and len) and has no return value (the string is modified in place); this function generates an anagram of a string by swapping random pairs of characters in the string. Random numbers are generated using the random() function, which you don’t have to write and has the prototype as shown on the right.Translate random_anagram into a MIPS assembly language function. Use the rem pseudoinstruction for the mod (%) operator. You will not be graded on the efficiency of your code, but you must follow all MIPS conventions. Comment your code!!!voidrandom_anagram(char *str, int len) { for (int i = 0 ; i < 100 ; ++ i) { int index1 = random() % len; int index2 = random() % len; char temp = str[index1]; str[index1] = str[index2]; str[index2] = temp; }}int random();4Question 3: Concepts (15 points)Write a short answer to the following questions. For full credit, answers should not be longer than two sentences. 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 you need. 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 $raPointers in C:Declarartion: either char *char_ptr -or- char char_array[] for char cDereference: c = c_array[i] -or- c =*c_pointerTake address of: c_pointer = &cCategory Example Instruction MeaningArithmeticadd $t0, $t1, $t2 $t0 = $t1 + $t2sub $t0, $t1, $t2 $t0 = $t1 – $t2addi $t0, $t1, 100 $t0 = $t1 + 100mul $t0, $t1, $t2 $t0 = $t1 x $t2div $t0, $t1, $t2 $t0 = $t1 / $t2rem $t0, $t1, $t2 $t0 = $t1 mod $t2Register Settingmove $t0, $t1 $t0 = $t1li $t0, 100 $t0 = 100Data Transferlw $t0, 100($t1)lb $t0, 100($t1)$t0 = Mem[100 + $t1] 4 bytes$t0 = Mem[100 + $t1] 1 bytesw $t0, 100($t1)sb $t0, 100($t1)Mem[100 + $t1] = $t0 4 bytesMem[100 + $t1] = $t0 1 byteBranchbeq $t0, $t1, Label if ($t0 = $t1) go to Labelbne $t0, $t1, Label if ($t0 ≠ $t1) go to Labelbge $t0, $t1, Label if ($t0 ≥ $t1) go to Labelbgt $t0, $t1, Label if ($t0 > $t1) go to Labelble $t0, $t1, Label if ($t0 ≤ $t1) go to Labelblt $t0, $t1, Label if ($t0 < $t1) go to LabelSetslt $t0, $t1, $t2 if ($t1 < $t2) then $t0 = 1 else $t0 = 0slti $t0, $t1, 100 if ($t1 < 100) then $t0 = 1 else $t0 = 0Jumpj Label go to Labeljr $ra go to address in $rajal Label $ra = PC + 4; go to


View Full Document

U of I CS 232 - Exam 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

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?