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

MIPS Programming Practice Midterm 1 Solutions, Exams of Computer Architecture and Organization

Solutions to practice midterm 1 of the cs232 fall 2006 course, including c to mips translation, debugging mips code, cpu performance optimization, and conceptual questions.

Typology: Exams

Pre 2010

Uploaded on 03/16/2009

koofers-user-925
koofers-user-925 🇺🇸

5

(1)

10 documents

1 / 5

Toggle sidebar

Related documents


Partial preview of the text

Download MIPS Programming Practice Midterm 1 Solutions and more Exams Computer Architecture and Organization in PDF only on Docsity! CS232 Fall 2006 Practice Midterm 1 1. C to MIPS translation: Translate the following C function into MIPS. Assume that the functions getPivot and insertionSort have already been translated for you. Be sure to follow all calling con- ventions! void quickSort(int array[], int n) { // n = length of array int p; if(n <= 5) { insertionSort(array, n); } else { p = getPivot(array, n); // assume p > 0 quickSort(array, p); quickSort(array + p, n - p); } } 1 CS232 Fall 2006 Practice Midterm 1 2. Debugging MIPS: The following recursive C function getNode returns a pointer to the nth node of a linked- list. Each node of the list contains an int data field and a next field that is a pointer to the next node in the list. The inputs to the function are n and head (a pointer to the first node in the list). struct node{ int data; node* next; } node* getNode(int n, node* head) { if(n <= 0 || head == 0) // 0 == NULL pointer return 0; if(n == 1) return head; // current pointer return getNode(n-1, (*head).next); } An incorrect MIPS translation of getNode is given below: getNode: addi $sp, $sp, 4 # line 1 sw $ra, 0($sp) # line 2 bgt $a0, $zero, positive # line 3 bne $a1, $zero, positive # line 4 li $v0, 0 # line 5 positive: bne $a0, 1, recursive # line 6 li $v0, 1 # line 7 jr $ra # line 8 recursive: addi $a0, $a0, -1 # line 9 lw $s0, 0($a1) # line 10 add $s0, $s0, 4 # line 11 move $a1, $s0 # line 12 jal getNode # line 13 addi $sp, $sp, 4 # line 14 lw $ra, 0($sp) # line 15 jr $ra # line 16 Identify and correct all errors (including violations of calling conventions) in the above code. You may rewrite the code, or simply indicate the changes that you need to make. Errors Corrected code 2
Docsity logo



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