CS 260 Assignment #6 – The Hailstone Sequence (25 Points) Consider this series of numbers: XXXXXXXXXXStarting with a positive integer N , this series is computed with a simple iterative computation: •...

1 answer below »
Assignment is attached. It needs to be in MIPS assembly, people get it confused with assembly.


CS 260 Assignment #6 – The Hailstone Sequence (25 Points) Consider this series of numbers: 3 10 5 16 8 4 2 1 Starting with a positive integer N , this series is computed with a simple iterative computation: • If the current integer N is even, the next number is N/2 • If the current integer N is odd, the next number is N ∗ 3 + 1 • Repeat until N equals 1 This is called the Hailstone sequence and it is related to the Collatz conjecture. The conjecture states that eventually this series will converge to 1 no matter what positive starting integer is chosen. Here is another example of the series: 26 13 40 20 10 5 16 8 4 2 1. You are to write a MIPS assembly language program that does the following: • Prompt the user for an integer N . • Compute the hailstone sequence for the given number N and print the value produced at each step. You do not need to store the sequence of numbers, just compute them, print them. (It’s possible, in general, that N ∗ 3 + 1 will be too big to fit in a 32-bit number. We will avoid those cases in testing.) • Once the sequence reaches 1, print the number of iterations and terminate the program. • Feel free to use snippets of my multiplication code (posted in Canvas) to read and write to the terminal, multiply and to terminate your program. Note: there is a much easier way to multiply by 3. You must follow these restrictions: • Place your name in a comment on the first line of the file. • Write (at least) one function that computes N ∗ 3 + 1. The parameter N must be passed to the function in $a0, and the function must return N ∗3+1 in $v0. Call the function using standard MIPS conventions (using jal to call the function and jr to return from it). • You MAY NOT use the built-in MIPS instructions for multiply or divide. Use addition and shift instructions for multiplication and division, and the AND instruction for odd/even testing. • You must comment your code. • Be sure your code complies with output specification later in this document. Name your file hail.asm and submit it via Canvas. 1 Your program’s output must be structured as follows: • Print a neat prompt asking the user for the starting N value • Print a blank line between the completed prompt and the Hailstone sequence • Print the sequence, starting with N and ending with 1, space separated on a single line. • Print a blank line before the number of iterations. • Print the number of iterations, which should match the total number of values printed. Here are two example runs, based on the sequences earlier in the assignment: Enter starting N: 3 3 10 5 16 8 4 2 1 Iterations: 8 Enter starting N: 26 26 13 40 20 10 5 16 8 4 2 1 Iterations: 11 Grading breakdown is as follows: Value Category 5 pts General comments and style 5 pts Nicely rendered prompts and output 5 pts Appropriately called function(s) 10 pts Correctly calculates Hailstone sequence 2
Answered 1 days AfterNov 16, 2021

Answer To: CS 260 Assignment #6 – The Hailstone Sequence (25 Points) Consider this series of numbers:...

Gaurav answered on Nov 17 2021
115 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here