HW04: The Hailstone Sequence due Mon 23 Sep 23:59

Purpose

In this assignment you will learn/practice:

Description

Make sure you have the most recent version of the homework repository and do your work in the hw04 directory.

Write an assembly language program that calculates the length of the so-called hailstone sequence for the numbers 2 to 100,000 and displays the numbers whose sequence is 300 or more.

The hailstone function for a positive integer $n$ is defined as:

$\displaystyle f(n) = \left\{ \begin{array}{cc}
n/2 & \mbox{if } n \mbox{ is even} \\
3n+1 & \mbox{if } n \mbox{ is odd} \\
\end{array}
\right.
$

To obtain the hailstone sequence simply plug a number into the function to get a new number. Then plug that number into the function. Continue this process until the function produces 1. It has been conjectured that the sequence will coverge to 1 for all positive integers. This is still an open question.

As an example, the hailstone sequence for the number three is:

$\displaystyle 3 \rightarrow\ 10 \rightarrow\ 5 \rightarrow\ 16 \rightarrow\ 8 \rightarrow\ 4 \rightarrow\ 2 \rightarrow\ 1
$

For our purposes we'll say this sequence has a length of 7. This sequence is less than 300 so we would not include it in our output. Here is a partial sample of the output from my program:

26623 has length 307
34239 has length 310
35497 has length 310
35655 has length 323
  .    .    .     .
  .    .    .     .
  .    .    .     .

Submission Guidelines and Suggestions

When completed, push your committed work to bitbucket.

One of the challenges of writing assembly code is managing complexity. It can be tempting to try to write the entire program and then start debugging. As an alternative, try this sequence, stopping to test and verify after each step:

Assembly Language

Segmentation Fault Counter

1779736907