Computer Science homework help

User Generated

Uryyra91

Computer Science

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 */


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Similar Content

Related Tags