In mips assembly language

Assignment Help Basic Computer Science
Reference no: EM13679296

In MIPS Assembly language
1. Write a program to compute and output the first N prime numbers. The program should prompt the user to input the value for N. Your implementation should use a procedure test_prime that accepts a parameter n and tests if n is a prime number: test_primereturns 1 if n is prime, and 0 otherwise.
Hint:
1. A number is prime if and only if no numbers except 1 and itself divide it evenly. You can use a for-loop to check this.
2. To check if a number A can be divided evenly by a number B, use the division instruction div A, B. It puts the reminder of the division in the register HI and the quotient in the register LO.
3. To copy the value of HI to a general register, use the instruction mfhi. To copy the value of LO to a general register, use mflo.

2. Write a program named hanoi.s (or Hanoi.asm) to solve the the classic mathematical recreation, the Towers of Hanoi puzzle. You have to use recursions to solve the puzzle. Your program should first prompt the user to input the number of disks, and then solve the puzzle recursively, as illustrated in this C program hanoi.c. Your program should also print, in each recursion, the current number of disks on the pegs in the following format :
>spim hanoi.s
Enter the number of disks: 3
[3, 0, 0]
[2, 0, 1]
[1, 1, 1]
[1, 2, 0]
[0, 2, 1]
[1, 1, 1]
[1, 0, 2]
[0, 0, 3]
Since your implementation uses recursive procedures, it is important that you follow the procedure call convention, including the parameter passing and the register usage. Otherwise, your program may not work correctly.
The global variable number_of_disks in hanoi.c is used to store the current number of disks on the pegs 0, 1, and 2. You can implement it as a global variable in your assembly program as well.

C Program of puzzle:
/* move n smallest disks from start to finish using
extra */
void hanoi(int n, int start, int finish, int extra){
if(n != 0){
hanoi(n-1, start, extra, finish);
print_string("Move disk");
print_int(n);
print_string("from peg");
print_int(start);
print_string("to peg");
print_int(finish);
print_string(".n");
hanoi(n-1, extra, finish, start);
}
}
main(){
int n;
print_string("Enter number of disks>");
n = read_int();
hanoi(n, 1, 2, 3);
return 0;
}

Reference no: EM13679296

Questions Cloud

Are dirty-unpleasant jobs an inevitable part of any economy : Are dirty, dangerous, and unpleasant jobs an inevitable part of any economy?
The iso network management model helps it managers : The ISO Network Management Model helps IT managers
Explain what is a thermal equilibrium : Explain what is a thermal equilibrium, Find what is the SI unit of the specific heat
Evaluate the change in the truck kinetic energy : As a 1220 kilogram truck travels up a 15.4 meter high hill, the non conservative forces of friction, obtain the change in the truck kinetic energy as it travels from the bottom of the hill to the top of the hill
In mips assembly language : In MIPS Assembly language
Write the sql query to return all of the information : Write the SQL query to return all of the information
Estimate the capacitance of the system : Two conductors having net charges of +13 µC and -13 µC have a potential difference of 13.0 Volt between them. Estimate the capacitance of the system
Create a program called sum of numbers : Create a program called Sum of Numbers
Evaluate what is the value of the capacitance : When a 18 Volt battery is connected to the plates of a capacitor; it stores a charge of 21.0 µC. Evaluate what is the value of the capacitance

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Discuss whether a rebalance operation is required or not

Consider an AVL tree with 9 nodes containing positive integer values in of your own from the interval 1 .. 99.

  A topic relevant to current information

Select two articles on a topic relevant to current information security trends and describe its impact on business; assess the steps industry should take to address it. Formatting: APA style paper, double spaced, two pages, Cover page, reference ..

  Describe the considerations

Describe the considerations that organizations and investigators must take into account when determining the appropriate tools to use, while knowing that the tool will be used to support legal proceedings.

  Prepare a project task list to include all the detailed task

You are the data transformation specialist for the first data warehouse project in an airlines company. Prepare a project task list to include all the detailed tasks needed for data extraction and transformation.

  Write a sequential search function to search for a number

Write a sequential search function to search for a number in the unsorted array created in 1a. Count the number of comparisons and display the count at the end of the search. Test the search function by searching for the number 101.

  Imagine and describe three general scenarios

Imagine and describe three general scenarios where network problems

  Find the distance from the point

find the distance from the point (1 2 3) from each of the following 1) the line of intersection of the plane p1 x-2y-3z=4 and p2 ; 2x-y +5z=1 2) the plane perpendicular to the ( X+2)/3= (Y-1)/-2 = (Z-3)/-1

  Convert following base ten numbers their binary equivalent

Convert each of the following base ten numbers to their binary equivalent: a. 16.4 b. 39 c. 48.67

  How would you use one of the standard mib objects

How would you use one of the standard MIB objects to determine which one of the stations in a LAN is functioning as a bridge to the external network?

  Profit do you make on each wafer

If your demand is 50,000 Woods chips per month and 25,000 Markonchips per month, and your facility can fabricate 150 wafers a month, how many wafersshould you make of each chip?

  Write limitations of present windows computers

Write down some limitations of present Windows 95 and 98 computers for use in context of this library, compared to more modern operating system?

  Storage of an unordered collection of items

Storage of an unordered collection of items that facilitates efficient, random access of items based on an item's position in the collection.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd