Lab 8: Recursion -- 3/3/2020

COSC 2200, Spring 2020

Marquette University, Department of Computer Science

Click here for the solution to this problem

Description

In our eighth lab, you and your partner will build a recursive ARM program, as described below.

Steps

Find your lab partner. Then:

Factorial (recursive solution)

Using your current knowledge of ARM instructions (including push and pop), build a program that computes the factorial of a positive integer. It should continue to ask for integers until EOF (Control+D). Your program should push a temporary register (e.g. R1) and LR onto the stack, and call itself with "bl", telling the link register where to return to when the main function is complete. After the "bl" call to itself, you should form the result. Keep in mind the role of the link register -- it will return to this location once for each recursive call you made, working its way back down the stack (popping each time). At this point in the program, print the result of the multiplication (you should use r0), as well as the stacked r1 value, so you can observe how they change as your program runs.

Example:


	Factorial Calculator
	? 4
	R0: 1, R1: 2
	R0: 2, R1: 3
	R0: 6, R1: 4
	Result: 24
	? 3
	R0: 1, R1: 2
	R0: 2, R1: 3
	Result: 6
	? 5
	R0: 1, R1: 2
	R0: 2, R1: 3
	R0: 6, R1: 4
	R0: 24, R1: 5
	Result: 120
	? 11
	R0: 1, R1: 2
	R0: 2, R1: 3
	R0: 6, R1: 4
	R0: 24, R1: 5
	R0: 120, R1: 6
	R0: 720, R1: 7
	R0: 5040, R1: 8
	R0: 40320, R1: 9
	R0: 362880, R1: 10
	R0: 3628800, R1: 11
	Result: 39916800
	?

	All user process have completed.