A3: Local Variables & Loops

Great, you have successfully written your first (simple) subroutine! You may have noticed that the subroutine from the previous assignment did not do too much (in fact it acted as a simple inc instruction). This is somewhat different for this assignment, which will require you to implement a more complex subroutine using some common programming constructs such as loops and conditions.


Assignment

Write a program that asks the user for a signed 64-bit integer base (aa) and an unsigned 64-bit integer exponent (bb) and then prints the base raised to the exponent (aba^b). The result should be calculated using a subroutine.

Subroutine

The subroutine should have the signature:

int64_t my_pow(int64_t base, uint64_t exponent)

As the name suggests, it should raise the given base to the given exponent and return the result.

Main Program

Your main program should get the needed input from the user, call my_pow to calculate the result, and then print the result. The final program output should look like this:

Enter a base: <a>
Enter an exponent: <b>
<a>^<b> = <a^b>

where <a> and <b> are the given inputs and <a^b> is the value of a raised to the power of b.

Hint: If you are unsure about the exact requirements for the input, it may help to have a look at the tests on CodeGrade. They show exactly what output is expected for which inputs.


  1. Write a (pseudocode) specification for your my_pow subroutine. You may get your specification checked by a TA if you want to. Alternatively, you may want to implement the specification in a higher-level language (like Python or C++) first to test for correctness.

  2. Implement your specification in Assembly (as the my_pow subroutine in the framework). You may want to call it with hard-coded arguments and check the return value with a debugger for now - thereby you can narrow down the source of potential errors.

  3. Write the remaining parts of the program - namely prompting for and retrieving input from the user and pretty-printing the output. Make sure to use the appropriate format specifiers for reading the base and exponent.


Required Knowledge

The previous assignments already introduced many of the concepts you will need for this assignment. All of these concepts are needed again here, and for most in a slightly more extensive way.

  • Additionally to those concepts, you will need to know how to use some common Programming Constructs in Assembly.

  • You may furthermore revisit the process of writing a pseudocode specification and subsequently transforming that specification into an Assembly program, as described on the page about the Example Program.

Last updated