Exercise 5: Loopy Cube Roots

Using the online GCC/GAS assembler (as for the previous exercise), write an assembly program which computes integer cube roots using just the 64-bit registers %rax, %rbx, %rcx, and %rdx. For example, the cube root of 27 is 3. If the cube root of a number is a float, truncate the result. For example, the cube root of 70 will be computed as 4 (since 43 = 64). Assume the target number (the number you are taking the cube root of) is positive and in %rcx. Compute the answer into %rax. Do this by looping from 0 up to a value N such that where N3 <= %rcx and (N+1)3 > %rcx.

Hints

A general plan for solving this sort of problem:

  1. Writing a solution to this in a high level language like Java or C++.

  2. Convert the variable names to register names; part of this is being clear which register will hold what value.

  3. Identify the loops and if statements; you will need labels for these. Pick label names that correspond to what is being computed.

  4. Construct fragments of code computing each step in your high-level code.

  5. Hand-check the resulting code, correcting errors as you go. It will be much easier to correct the errors this way than to try to work out what when wrong in computed answers.

  6. Run the code on examples.

Submission

As for the previous exercise, use the debugger to show that your code computes the correct result. Submit capture screen shots for three values: 729, 728, and 99. Place these into a single document (with very thin margins) and submit it as a PDF. Be sure to include your program listing in at least one of the screen shots, and be sure the input in %rcx is visible as well as the result in %rax.

You may work with other students on this assignment, but each must turn in screen shots of their own code.