programs辅导、C++编程语言调试、c/c++讲解、辅导data

- 首页 >> Java编程
Minimal Submitted Files
 
You are required to turn in the following source file:
assignment6.s
Objectives:
 
-write assembly language programs to:
-define procedures/functions and call them.
-create loops
-use syscall operations to display integers and strings on the console window
-use syscall operations to read integers from the keyboard.
 
Assignment Description:
 Implement a MIPS assembly language program that defines main, readArray, printArray, and changeArrayContent procedures/functions.
The readArray takes an array of integers as its parameter, asks a user how many numbers will  be entered, then reads in integers from a user to fill the array.
The printArray takes an array of integers as its parameter, prints each integer of the array.
The changeArrayContent procedure/function takes parameters of arrays of integers,  an integer that specify how many integers were entered by a user, a maximum array size, and also asks a user to enter an integer. Then it goes through each element of the array, and check if it is divisible by the entered integer, it multiplies it by the entered integer. Then it calls printArray to print out the changed content.  (Please see the C program below).
The main procedure/function calls readArray function to populate the array, calls printArray to print out its original content, then it asks a user to enter how many times the operation should be repeated, then calls changeArrayContent to change it content,

Please see the following C program to understand how it should work.
If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it.  
Name your source code file assignment6.s.
You can create an array in the following way:
numbers:     .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
The following shows how it looks like in a C program:
 

int readArray(int array[], int arraysize)
{
int num, i = 0;
int length;

printf("Specify how many numbers should be stored in the array (at most 11):\n");
scanf("%d", &length);

while (i < arraysize && i < length)
{
printf("Enter an integer: \n");

//read an integer from a user input and store it in num1
scanf("%d", &num);
array[i] = num;

i++;
}

return length;
}

//The printArray function prints integers of the array
void printArray(int array[], int arraysize, int length)
{
int i;

i = 0;
while (i < arraysize && i < length)
{
printf("%d\n", array[i]);
i++;
}

return;
}


//The changeArrayContent reads in an integer
//Then it goes through the parameter array, and if an element
//is divisible by the entered integer, then it multiplies the element
//by the entered integer.
void changeArrayContent(int numbers[], int arraysize, int length)
{
int i;
int num1;

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

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


//It goes through each element of array
//and change their values if the condition holds
i = 0;
while (i < arraysize && i < length)
{
if (numbers[i]%num1 == 0)
numbers[i] = numbers[i]*num1;

i++;
}

printf("\nResult Array Content:\n");
printArray(numbers, arraysize, length);

return;
}
//The main reads in an array content,
//then it prints it,
//then it asks a user how many time to repeat
//the changeArrayContent operation.
void main()
{
int arraysize = 12, length;
int numbers[arraysize];
int howMany;
int i;

length = readArray(numbers, arraysize);
printf("\nOriginal Array Content:\n");
printArray(numbers, arraysize, length);

printf("Specify how many times to repeat:\n");
scanf("%d", &howMany);

i=0;
while (i < howMany)
{
changeArrayContent(numbers, arraysize, length);
i++;
}

return;
}
The following is a sample output (user input is in bold):
Specify how many numbers should be stored in the array (at most 11):

站长地图