Starting from:

$30

CSE230-Assignment 5 Solved

Assignment Description:

An array of integers can be assigned to a memory address in the .data section of a MIPS assembly language program as show below. Here the length of the array is stored first, and then the elements of the array numbers next.

 Implement a MIPS assembly language program to perform the functionality of the following C program and print the updated array content, by listing each integer in it.

It should ask a user to enter three integers, an ending index, an integer, and another integer to use for a comparison. It should examine only the elements in the array located from the index 0 to the entered ending index to check if each of them is greater the smallest of the last two entered numbers and is less than the largest of the last two entered numbers, then if it is, then change each such element in the array within the range according to the calculation given in the C program umbers[j] = numbers[j]*num1 + num2. For instance, if a user enters 8, enters 3, then enters 23, then the output will be the following:

2

80

23

-7

68

-17

56

-4

23

-26

27

i.e., the numbers that are located between the index 0 and 7 are examined to see if each of them is greater than 3 and less than 23. then each of such element is changed.

If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it.  Name your source code file assignment5.s.

                     .data numbers_len:         .word     11 numbers:             .word     2, 19, 23, -7, 15, -17, 11, -4, 23, -26, 27

 

The following shows how it looks like in a C program:

 

int numbers_len = 11; int numbers[11] = {2, 19, 23, -7, 15, -17, 11, -4, 23, -26, 27};

int endingIndex, num1, num2, temp;

int j;

printf("Enter an ending index:\n");

//read an integer from a user input and store it in endingIndex scanf("%d", &endingIndex);

printf("Enter an integer:\n");

//read an integer from a user input and store it in num1 scanf("%d", &num1);

 

printf("Enter another integer:\n");

//read an integer from a user input and store it in num2 scanf("%d", &num2);

 

//if num1 is larger than num2, swap them if (num1 > num2)

{

    temp = num1;      num1 = num2;      num2 = temp;

}

//At this point num1 will always be less or equals to num2

 

//changing the array content for (j = 0; j < endingIndex && j < numbers_len; j = j+1)

{

     if (numbers[j] > num1 && numbers[j] < num2)

      {

       numbers[j] = numbers[j]*num1 + num2;

     }

}

printf("Result Array Content:\n"); for (j = 0; j < numbers_len; j = j+1)

{       printf("%d\n", numbers[j]); }

 

 

The following is a sample output (user input is in bold):

 

 

Enter an ending index:

8

Enter an integer:

3

Enter another integer:

23

Result Array Content:

2

80

23

-7

68

-17

56

-4

23

-26 27

--------------------------------------------------

The following is another sample output:

 

--------------------------------------------------

Enter an ending index:

5

Enter an integer:

14

Enter another integer:

-2

Result Array Content:

10

19

23

-7

15

-17

11

-4

23

-26 27

--------------------------------------------------

More products