Assignment5: Function Implementation on MIPS_Solved

$35.00 $29.00

Write a MIPS program to do the following: The program should input an ​integer​of at most 4 decimal digits – this is the modulus, ​n​. The program should input a ​string​of 12 ​decimal​digits (most significant digit first). This represents a 12-digit integer(padded with 0s, if needed). Call it ​a​. The program should compute ​a​mod ​n​and…

5/5 – (1 vote)

You’ll get a: zip file solution

 

Description

5/5 – (1 vote)
  1. Write a MIPS program to do the following:

The program should input an integerof at most 4 decimal digits – this is the modulus, n. The program should input a stringof 12 decimaldigits (most significant digit first). This represents a 12-digit integer(padded with 0s, if needed). Call it a.

The program should compute amod nand display this value on the screen (result should be between 0 and n-1, i.e., 0 a mod n n-1).

Your program should prompt the user for input as shown below.

Your program should include a couple of subroutines. (Ideally, at least one of them should

be a non-leaf routine.)

Constraints:n>=1, integer represented by a>=0.

Sample run:

Enter modulus:1000

Enter string of 12 decimal digits:123456789012

123456789012 mod 1000 = 12 Wish to continue?:Y

Enter modulus:25

Enter string of 12 decimal digits:246801357988

246801357988 mod 25 = 13 Wish to continue?: N

Output by your program is in blue color.

You may wish to use the following easily provable theorems from Modulo Arithmetic:

(a + b) mod n = ( (a mod n) + (b mod n) ) mod n

and

(a * b) mod n = ( (a mod n) * (b mod n) ) mod n

  1. Implement a recursive function to compute the gcd of two integers. (The gcd is the greatest common divisor or common factor shared by two integers. For example, gcd(210, 112) = 14.)

For two integers m and n , m >= n , gcd ( m , n ) = n if m % n = 0.

Otherwise, gcd( m , n ) = gcd( n , m % n ).

So, gcd(210,112) = gcd(112,98) = gcd(98,14) = 14.

Your function should prompt the user for the two integer inputs m and n and then print the value of gcd ( m , n ).

Constraints:m,n >= 1.

Sample run:

Enter m:210

Enter n:112

gcd(210,112) = 14

Wish to continue?:Y

Enterm:462

Entern:363

gcd(462,363) = 33

Wish to continue?:N

Output by your program is in blue color.

Assignment5: Function Implementation on MIPS_Solved
$35.00 $29.00