In mips assembly


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;
}

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: In mips assembly
Reference No:- TGS0932872

Expected delivery within 24 Hours