A3: Local Variables & Loops
Last updated
Last updated
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.
While the previous assignments may still have been solvable without caring all too much for things like calling conventions or stack setup, the complexity of this assignment requires significantly more attention to detail - mostly to avoid confusing and convoluted bugs in your program.
Write a program that asks the user for a signed 64-bit integer base () and an unsigned 64-bit integer exponent () and then prints the base raised to the exponent (). The result should be calculated using a subroutine.
The subroutine should have the signature:
As the name suggests, it should raise the given base to the given exponent and return the result.
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:
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.
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.
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.
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.
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.