Question

In: Computer Science

Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that...

Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that generates and stores a specified number of random numbers each of whose values are between 0 and 1000 in an array

Solutions

Expert Solution

Here i am providing the answer. Hope it helps.

.LC0:

        .ascii  "Enter the number of integers :  \000"

.LC1:

        .ascii  "%d\000"

.LC2:

        .ascii  "\012The array numbers are :  \000"

.LC3:

        .ascii  "%d \000"

main:

        daddiu  $sp,$sp,-144

        sd      $31,136($sp)

        sd      $fp,128($sp)

        sd      $28,120($sp)

        sd      $23,112($sp)

        sd      $22,104($sp)

        sd      $21,96($sp)

        sd      $20,88($sp)

        sd      $19,80($sp)

        sd      $18,72($sp)

        sd      $17,64($sp)

        sd      $16,56($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu  $28,$28,%lo(%neg(%gp_rel(main)))

        move    $2,$sp

        sd      $2,32($fp)

        move    $4,$0

        ld      $2,%call16(time)($28)

        move    $25,$2

        nop

        sll     $2,$2,0

        move    $4,$2

        ld      $2,%call16(srand)($28)

        move    $25,$2

        nop

        ld      $2,%got_page(.LC0)($28)

        daddiu  $4,$2,%got_ofst(.LC0)

        ld      $2,%call16(printf)($28)

        move    $25,$2

        nop

        daddiu  $2,$fp,24

        move    $5,$2

        ld      $2,%got_page(.LC1)($28)

        daddiu  $4,$2,%got_ofst(.LC1)

        ld      $2,%call16(__isoc99_scanf)($28)

        move    $25,$2

        nop

        lw      $2,24($fp)

        move    $3,$2

        daddiu  $3,$3,-1

        sd      $3,8($fp)

        move    $3,$2

        move    $23,$3

        move    $22,$0

        dsrl    $3,$23,59

        dsll    $18,$22,5

        or      $18,$3,$18

        dsll    $19,$23,5

        move    $3,$2

        move    $21,$3

        move    $20,$0

        dsrl    $3,$21,59

        dsll    $16,$20,5

        or      $16,$3,$16

        dsll    $17,$21,5

        dsll    $2,$2,2

        daddiu  $2,$2,3

        daddiu  $2,$2,15

        dsrl    $2,$2,4

        dsll    $2,$2,4

        dsubu   $sp,$sp,$2

        move    $2,$sp

        daddiu  $2,$2,3

        dsrl    $2,$2,2

        dsll    $2,$2,2

        sd      $2,16($fp)

        sw      $0,0($fp)

        b       .L2

        nop

.L3:

        ld      $2,%call16(rand)($28)

        move    $25,$2

        nop

        li      $3,1098383360                 # 0x41780000

        ori     $3,$3,0x749f

        mult    $2,$3

        mflo    $3

        mfhi    $4

        dins    $3,$4,32,32

        dsrl    $3,$3,32

        sll     $3,$3,0

        sra     $4,$3,8

        sra     $3,$2,31

        subu    $4,$4,$3

        li      $3,1001           # 0x3e9

        mul     $3,$4,$3

        subu    $2,$2,$3

        move    $3,$2

        ld      $4,16($fp)

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$4,$2

        sw      $3,0($2)

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

.L2:

        lw      $2,24($fp)

        lw      $3,0($fp)

        slt     $2,$3,$2

        bne     $2,$0,.L3

        nop

        ld      $2,%got_page(.LC2)($28)

        daddiu  $4,$2,%got_ofst(.LC2)

        ld      $2,%call16(printf)($28)

        move    $25,$2

        nop

        sw      $0,0($fp)

        b       .L4

        nop

.L5:

        ld      $3,16($fp)

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$3,$2

        lw      $2,0($2)

        move    $5,$2

        ld      $2,%got_page(.LC3)($28)

        daddiu  $4,$2,%got_ofst(.LC3)

        ld      $2,%call16(printf)($28)

        move    $25,$2

        nop

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

.L4:

        lw      $2,24($fp)

        lw      $3,0($fp)

        slt     $2,$3,$2

        bne     $2,$0,.L5

        nop

        ld      $sp,32($fp)

        nop

        move    $sp,$fp

        ld      $31,136($sp)

        ld      $fp,128($sp)

        ld      $28,120($sp)

        ld      $23,112($sp)

        ld      $22,104($sp)

        ld      $21,96($sp)

        ld      $20,88($sp)

        ld      $19,80($sp)

        ld      $18,72($sp)

        ld      $17,64($sp)

        ld      $16,56($sp)

        daddiu  $sp,$sp,144

        j       $31

        nop

IMAGE OF OUTPUT

Thnak you. give me a like. it helPs me a lot.


Related Solutions

Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[],...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[], int size); 2. Write a function to generate an array of random integers. void random_array (int arr[], int size, int range); The scale of numbers should be 1 to range. 3. Write a function to find the sum of a sequence of number. int sum (int arr[], int size); 4. Write a function rotate(arr[], d, n) that rotates arr[] of size n by d...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];        arr[i] = arr[j];        arr[j] = temp; } void function(int arr[], int length) {        for (int i = 0; i<length / 2; i++)               swap(arr, i, (length / 2 + i) % length); } If the input to the function was int arr[] = { 6, 1, 8, 2, 5, 4, 3, 7 }; function(arr,8); What values would be stored in the array after calling the...
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
   private static void merge(int arr[], int l, int m, int r) {        //...
   private static void merge(int arr[], int l, int m, int r) {        // Find sizes of two subarrays to be merged        int n1 = m - l + 1;        int n2 = r - m;        /* Create temp arrays */        int L[] = new int[n1];        int R[] = new int[n2];        /* Copy data to temp arrays */        for (int i = 0; i...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of length at least two as an argument, and swaps the smallest value of the array into the 0th position and swaps the largest value of the array into the last position. For example, if int[] a = {4, 3, 2, 6, 1, 5}, the method call minMax(a) should modify the array so that it is {1, 3, 2, 5, 4, 6}. The method should...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int&...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int& numberUsed) { cout << "Enter up to " << size << " nonnegative whole numbers.\n" << "Mark the end of the list with a negative number.\n"; int next, index = 0; cin >> next; while ((next >= 0) && (index < size)) { a[index] = next; index++; cin >> next; } numberUsed = index; } int search(const int a[], int numberUsed, int target) {...
IN C Write a function in the form: void play( int key, int duration) // duration...
IN C Write a function in the form: void play( int key, int duration) // duration units are tenths of a second which generates and prints samples of sin(w*t) for t=0,1,2,...,n-1 which represent a tone corresponding to piano key number key, where: n = (duration/10.0)*8000 w = (2π440rkey-49)/8000 r = 21/12 In the main program call your function to play the first three notes of three blind mice.
Debug this code getting segmentation faults. //array_utils.h int contains(const int *arr,int size , int k); int...
Debug this code getting segmentation faults. //array_utils.h int contains(const int *arr,int size , int k); int containsWithin(const int *arr,int size , int k,int i , int j); int *paddedCopy(const int *arr,int oleSize , int newSize); void reverse(int *arr,int size); int *reverseCopy(const int *arr,int size); //array_utils.c #include"array_utils.h" #include<stdlib.h> int contains(const int *arr,int size , int k){    int i=0;    for(i=0;i<size;i++){        if(arr[i] == k)return 1;    }    return 0; } int containsWithin(const int *arr,int size , int k,int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT