Question: Task 1 : C# Program Study the following C# program bellow ( also attached to the assignment ) that performs the following operations: Defines an

Task 1: C# Program
Study the following C# program bellow (also attached to the assignment) that performs the following operations:
Defines an array of integers with at least 10 elements.
Calculates the sum of the elements in the array.
Determines the difference between the largest and smallest elements in the array.
Implements a simple function that multiplies two numbers and returns the result.
Task 2: MIPS Assembly Translation (50 points)
Translate the C# program shown in Task 1 into MIPS assembly code. Your MIPS program mainly contains some of the instructions that you studied in your class such as add, sub, lw, sw, addi, bne, j, jal, beq, sll, srl, slt, slti, and jr.
Implement a leaf procedure to multiply two numbers.
Implement a non-leaf procedure that calls the leaf procedure and uses its result.
Include comments on each line to explain the MIPS assembly instructions used.
C# Code:
using System;
class Program
{
static void Main()
{
// Task 1: Define an array of integers with at least 10 elements.
int[] numbers ={1,3,5,7,9,2,4,6,8,10};
// Task 2: Calculate the sum of the elements in the array.
int sum = CalculateSum(numbers);
// Task 3: Determine the difference between the largest and smallest elements in the array.
int difference = FindMax(numbers)- FindMin(numbers);
// Task 4: Implement a simple function that multiplies two numbers and returns the result.
int product = Multiply(5,3);
// Output results to the console
Console.WriteLine("Sum of array elements: "+ sum);
Console.WriteLine("Difference between the largest and smallest elements: "+ difference);
Console.WriteLine("Product of 5 and 3: "+ product);
}
// Calculates the sum of an array of integers
static int CalculateSum(int[] array)
{
int sum =0;
for (int i =0; i < array.Length; i++)
{
sum += array[i];
}
return sum;
}
// Finds the maximum value in an array of integers
static int FindMax(int[] array)
{
int max = array[0];
for (int i =1; i < array.Length; i++)
{
if (array[i]> max)
{
max = array[i];
}
}
return max;
}
// Finds the minimum value in an array of integers
static int FindMin(int[] array)
{
int min = array[0];
for (int i =1; i < array.Length; i++)
{
if (array[i]< min)
{
min = array[i];
}
}
return min;
}
// Multiplies two integers and returns the result
static int Multiply(int a, int b)
{
return a * b;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!