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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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