Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions