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

  Write the code for invoking a method named sendobject

Write the code for invoking a method named sendObject . There is one argument for this method which is of type Customer . Assume that there is a reference to an object of type Customer , in a variable called John_Doe . Use this reference as your a..

  Make report to print gross earnings and tax payable

Your report is to print the gross earnings, tax payable, medical levy and net earnings for each employee. At the end of the report, print the total gross earnings, total tax, total medical levy and total net earnings.

  Evaluate integer expressions

Evaluate integer expressions - evaluation of expressions must recognize the standard precedence

  Calculating flight times

Chapter 1 Programming Challenges #3 Training Workshops and #4 Investment Tracking. Chapter 2 Programming Challenges #3 Winter Sports Rentals and #5 Calculating Flight Times

  Explaining mandatory access control implementation

How are Novell AppArmor and the Red Hat "targeted" SELinux policy similar? Is either a true Mandatory Access Control implementation. If not, explain why.

  Create class includes instance variables automatic propertie

Create a class called Employee that includes three pieces of information as either instance variables or automatic properties - a firstname (type string), a last name (type string) and a monthly salary (decimal)

  Utilize the internet to research recent investigations

utilize the internet to research recent investigations court cases new technological developments partnerships or other

  The rigor of a methodology be useful

The rigor of a methodology be useful

  What know by statement mydog setname bowser

what do you know by the following statement: myDog.setName("Bowser")

  Implement this function in assembly language

Implement this function in assembly language and write a test program that calls the function several times, passing it different values. Display all results on the screen.

  Design a 8m x 32 bit memory board

design a 8M x 32 bit memory board. You may use only 256K x 8 bit RAM chips with full parallel addressing.

  Receiver initiated distributed scheduling algorithms

Receiver initiated distributed scheduling algorithms suppose task pre-emption at the sender site.

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