Computers and Technology
Computers and Technology, 03.03.2020 05:43, MC2007

You are required to turn in the following source file:

assignment7.s

Objectives:

-write assembly language programs to:
-define a recursive procedure and call it.
-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", and "function1" procedures.

The function1 is recursive and should be defined as:

function1(n) = 2*n if n <= 4

= n*function1(n-2) + function1(n-3) + n otherwise.

The main asks a user to enter an integer for n and calls the function1 by passing the n value, then prints the result. If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it. Name your source code file assignment7.s.

C program that will ask a user to enter an integer, calls the fuction1, and prints the returned value from the function1.

// The function1 is a recursive procedure defined by:
// function1(n) = 2*n if n <= 4
// = n*function1(n-2) + function1(n-3) + n otherwise.

int function1(int n)
{
if (n <= 4)
{
return 2*n;
}
else
{
int comp = n*function1(n-2) + function1(n-3) + n;

return comp;
}
}

// The main calls function1 by entering an integer given by a user.
void main()
{
int ans, n;

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

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

ans = function1(n);

// print out the solution computed by function 1
printf("The solution is: %d\n", ans);

return;
}

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

Enter an integer:
8
The solution is: 527



What to turn in:

-Upload your assignment7.s file through the assignment submission link in the Blackboard by the assignment deadline. You must have your name, email address, program description, and other information in the header block as it was described in the assignment 1, and your programs should be well commented.

Each procedure needs to have a header using the following format:


# Procedure findMax
# Description:
# parameters: $a0 = address of array, $a1 = length
# return value: $v0 = max
# registers to be used: $s3 and $s4 will be used.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:50, laurentsofia09
Assume that you have an sorted array of records. assume that the length of the array (n) is known. give two different methods to search for a specific value in this array. you can use english or pseudo-code for your algorithm. what is the time complexity for each algorithm and why?
Answers: 1
image
Computers and Technology, 22.06.2019 11:10, golderhadashaowtatz
Which are not examples of chronic or persistent stress? moving
Answers: 1
image
Computers and Technology, 22.06.2019 11:40, malibu777
Design a pos circuit that displays the letters a through j on a seven-segment indicator. the circuit has four inputs w, x, y, and z which represent the last 4 bits of the uppercase ascii code for the letter to be displayed. thus, if wxyz = 0001 then "a" will be displayed. (any answer with 22 or fewer gates and inverters, not counting any for the inputs, is acceptable)
Answers: 2
image
Computers and Technology, 24.06.2019 17:40, michaelandtammytrice
Create a file called favorite_foods, and list your favorite foods, entering five or six or more. press enter after each favorite food so it appears on its own line (make certain you also press enter after the final food item). after the file is created, add two more foods you like that are not on the list (press enter after the final food item). view the list of foods to make certain the two items you added appear at the end of the list
Answers: 2
Do you know the correct answer?
You are required to turn in the following source file:

assignment7.s

Objecti...

Questions in other subjects:

Konu
Mathematics, 23.12.2020 14:00
Konu
Chemistry, 23.12.2020 14:00