Computer Science homework help

Oct 30th, 2014
Anonymous
Category:
Programming
Price: $15 USD

Question description

Take the following C code. (  see  file fib.c )   1.)  Compile it and get results. 2.)  Convert C code to MIPS. 3.) ...

  • Take the following C code. (  see  file fib.c )

    1.)  Compile it and get results.

    2.)  Convert C code to MIPS.

    3.)  Using SPIM report on register step by stem using snip/or cut and copy screen shots.

    CODE:

    /* File:  count_sort.c

     * Purpose:  Implement count sort of a list of ints

     *

     * Compile:  gcc -g -Wall -o count_sort count_sort.c

     * Run:  ./count_sort

     *

     * Input:  n (number of elements)

     *  elements of list

     * Output:  sorted list

     *

     * Note:  List is statically allocated.  Recompile if n > 100

     */

    #include <stdio.h>

    #include <stdlib.h>

    #define MAX 100

    void Read_list(int list[], int n);

    void Count_sort(int list[], int n);

    int  Fnd_pos(int val, int i, int list[], int n);

    void Copy_list(int new_list[], int list[], int n);

    void Print_list(int list[], int n);

    int main(void) {

      int list[MAX], n;

      scanf("%d", &n);

      Read_list(list, n);

    // Print_list(list, n);

      Count_sort(list, n);

      Print_list(list, n);

      return 0;

    }  /* main */

    void Read_list(int list[], int n) {

      int i;

      for (i = 0; i < n; i++)

      scanf("%d", &list[i]);

    }  /* Read_list */

    /* Sort list of n elements by "counting"

     * number of elements less than each element,

     * and using the count as the subscript in

     * a new list

     */

    void Count_sort(int list[], int n) {

      int i, loc, new_list[MAX];

      for (i = 0; i < n; i++) {

      loc = Fnd_pos(list[i], i, list, n);

      new_list[loc] = list[i];

      }

      Copy_list(new_list, list, n);

    }  /* Count_sort */

    /* Find the position to insert val among the elements 

     * in list by counting the number of elements "less than"

     * val.  In the case of a tie, an element list[j] is

     * considered "less than" val if j < i.

     */

    int  Fnd_pos(int val, int i, int list[], int n) {

      int j, count = 0;

      for (j = 0; j < n; j++)

      if (list[j] < val)

      count++;

      else if (list[j] == val && j < i)

      count++;

      return count;

    }  /* Fnd_pos */

    /* Copy contents of new_list into list.  Both store

     * n elements

     */

    void Copy_list(int new_list[], int list[], int n) {

      int i;

      for (i = 0; i < n; i++)

      list[i] = new_list[i];

    }  /* Copy_list */

    void Print_list(int list[], int n) {

      int i;

      for (i = 0; i < n; i++)

      printf("%d ", list[i]);

      printf("\n");

    }  /* Print_list */


Tutor Answer

(Top Tutor) swat
School: University of Maryland

Studypool has helped 1,244,100 students

Review from student
Anonymous
" Excellent job "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1824 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors